#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int napolje[40005]={0};
    int o,a,b,ab,n;
    int oz,az,bz,abz,x;
    string g,mg="moguce";
    cin >>n;
    cin>>oz,az,bz,abz;
    int h=0;
    int tutni=0;
    for(int i =0;i<n;i++){
        cin>>g>>x;
        if(g=="O"){
            if(x<=oz){
                oz=oz-x;
                napolje[h]=x;
                napolje[h+1]=0;
                napolje[h+2]=0;
                napolje[h+3]=0;
                h+=4;
            }
        }
        else{
            mg="nemoguce";
        }
        if(g=="A"){
            if(az>=x){
                az=az-x;
                napolje[h]=0;
                napolje[h+1]=x;
                napolje[h+2]=0;
                napolje[h+3]=0;
                h+=4;
            }
            else{
                if(az+oz>=x){
                napolje[h]=x-az;
                napolje[h+1]=az;
                napolje[h+2]=0;
                napolje[h+3]=0;
                oz=oz-x+az;
                az=0;
                }
                else{
                    mg="nemoguce";
                }
            }
        }
        if(g=="B"){
            if(bz>=x){
                bz=bz-x;
                napolje[h]=0;
                napolje[h+1]=0;
                napolje[h+2]=bz;
                napolje[h+3]=0;
                h+=4;
            }
            else{
                if(bz+oz>=x){
                napolje[h]=x-bz;
                napolje[h+1]=0;
                napolje[h+2]=bz;
                napolje[h+3]=0;
                oz=oz-x+bz;
                az=0;
                h+=4;
                }
                else{
                    mg="nemoguce";
                }
            }
        }
        if(g=="AB"){
            if(abz>=x){
                napolje[h]=0;
                napolje[h+1]=0;
                napolje[h+2]=0;
                napolje[h+3]=abz;
                abz=abz-x;
            }
            else{
                if(abz+az+bz>=x){
                    napolje[h]=0;
                    napolje[h+1]=243166;
                    napolje[h+2]=x-abz;
                    napolje[h+3]=abz;
                    abz=0;
                    tutni+=x-abz;
                }
                else{
                    if(az+bz+abz+oz>=x){
                    napolje[h]=x-az-abz-bz;
                    napolje[h+1]=az;
                    napolje[h+2]=bz;
                    napolje[h+3]=abz;
                    oz=oz-x+az+abz+bz;
                    az=0;
                    bz=0;
                    abz=0;
                    }
                    else{
                        mg="nemoguce";
                    }
                }
            }
        }
    }
    int br1,br2,br3,br4,m;
    if(mg=="nemoguce" || tutni>az+bz+oz){
        cout<< "nemoguce";
    }
    else{
        cout<<mg;
        for(int i=0;i<n;i++){
            br1=napolje[4*i];
            br2=napolje[4*i+1];
            br3=napolje[4*i+2];
            br4=napolje[4*i+3];
            if(br2==243166){
                m=br3;
                br1=max(oz-m,0);
                oz=max(oz-m,0);
                m=max(m-oz,0);
                br2=max(az-m,0);
                az=max(az-m,0);
                m=max(m-az,0);
                br3=max(bz-m,0);
                bz=max(bz-m,0);
            }
            cout<<br1<<" "<<br2<<" "<<br3<<" "<<br4<<endl;
        }
    }
    return 0;
}