#include <bits/stdc++.h>
using namespace std;

int naraspolaganjuO,naraspolaganjuA,naraspolaganjuB,naraspolaganjuAB;
int minusA,minusB;
int n,broj,IMA;
string s;
int o=0,a,b,ab;
int kolicina[1000000];
string tip[1000000];
int main(){

    cin>>n;
  cin>>naraspolaganjuO>>naraspolaganjuA>>naraspolaganjuB>>naraspolaganjuAB;
    for(int i=1;i<=n;i++){

        cin>>s;cin>>broj;

        if(s=="O"){kolicina[i]+=broj;tip[i]=s;o+=broj;}
       if(s=="A"){kolicina[i]+=broj;tip[i]=s;a+=broj;}
       if(s=="B") {kolicina[i]+=broj;tip[i]=s;b+=broj;}
        if(s=="AB"){kolicina[i]+=broj;tip[i]=s;ab+=broj;}



        IMA+=broj;
    }
    if(naraspolaganjuO<o){cout<<"nemoguce"<<endl;return 0;}

   naraspolaganjuO=naraspolaganjuO-o;



    minusA=a-naraspolaganjuA;
    minusB=b-naraspolaganjuB;
    if(minusA<0)minusA=0;
    if(minusB<0)minusB=0;

    if(naraspolaganjuO-((minusA)+(minusB))<0){cout<<"nemoguce"<<endl;return 0;}


    naraspolaganjuO=(naraspolaganjuO-(minusA)+(minusB));

    if(naraspolaganjuA>a)naraspolaganjuA-=a;else naraspolaganjuA=0;
    if(naraspolaganjuB>b)naraspolaganjuB-=b;else naraspolaganjuB=0;

    if(naraspolaganjuO+naraspolaganjuA+naraspolaganjuB<naraspolaganjuAB){cout<<"nemoguce"<<endl;return 0;}

    cout<<"moguce"<<endl;

    for(int i=1;i<=n;i++){       int minusminusA=0;
      if(tip[i]=="O")cout<<kolicina[i]<<" "<<0<<" "<<0<<" "<<0<<endl;

   if(tip[i]=="A"){
        if(minusA>=kolicina[i])
        {cout<<kolicina[i]<<" "<<0<<" "<<0<<" "<<0<<endl; minusA=minusA-kolicina[i];}
  else  if(minusA<kolicina[i])
    {cout<<minusA<<" "<<kolicina[i]-minusA<<" "<<0<<" "<<0<<endl; minusA=minusA-kolicina[i];}
   else  cout<<0<<" "<<kolicina[i]<<" "<<0<<" "<<0<<endl;
   }


   if(tip[i]=="B"){
        if(minusB>=kolicina[i])
        {cout<<kolicina[i]<<" "<<0<<" "<<0<<" "<<0<<endl; minusB=minusB-kolicina[i];}
   else if(minusB<kolicina[i])
    {cout<<minusB<<" "<<0<<" "<<kolicina[i]-minusB<<" "<<0<<endl; minusB=minusB-kolicina[i];}
   else cout<<0<<" "<<0<<" "<<kolicina[i]<<" "<<0<<endl;
   }



   if(tip[i]=="AB"){


cout<<0<<" "<<0<<" "<<0<<" "<<kolicina[i]<<endl;


        }
    }
        return 0;
        }