#include <bits/stdc++.h>

using namespace std;
int N;
int o,a,b,ab;
string krvgr;
int brjed;
int tacno=0;
int main(){
   cin>>N;
   cin>>o>>a>>b>>ab;
   for (int i=1;i<=N;i++){
      cin>>krvgr>>brjed;
      int x=0,y=0,z=0,q=0;
      if (krvgr=="O" and o>=brjed){
        o-brjed;
        tacno++;
        x+=brjed;
        cout<<brjed<<" "<<"0"<<" "<<"0"<<" "<<"0"<<endl;
      }
      else if (krvgr=="A" and a>=brjed){
        a-brjed;
        tacno++;
        y+=brjed;
        cout<<"0"<<" "<<brjed<<" "<<"0"<<" "<<"0"<<endl;
      }
      else if (krvgr=="A" and a+o>=brjed){
        a-a;
        o-(brjed-a);
        tacno++;
        y+=a;
        x+=brjed-a;
        cout<<o-(brjed+a)<<" "<<a<<" "<<"0"<<" "<<"0"<<endl;
      }
      else if (krvgr=="B" and b>=brjed){
        b-brjed;
        tacno++;
        z+=brjed;
        cout<<"0"<<" "<<"0"<<" "<<brjed<<" "<<"0"<<endl;
      }
      else if (krvgr=="B" and b+o>=brjed){
        b-b;
        o-(brjed-b);
        tacno++;
        z+=b;
        x+=brjed-b;
        cout<<o-(brjed+b)<<" "<<"0"<<" "<<b<<" "<<"0"<<endl;
      }
      else if (krvgr=="AB" and ab>=brjed){
        ab-brjed;
        tacno++;
        q+=brjed;
        cout<<"0"<<" "<<"0"<<" "<<"0"<<" "<<brjed<<endl;
      }
      else if (krvgr=="AB" and ab+b>=brjed){
        ab-ab;
        b-(brjed-ab);
        tacno++;
        q+=ab;
        z+=brjed-ab;
        cout<<"0"<<" "<<"0"<<" "<<b-(brjed+ab)<<" "<<ab<<endl;
      }
      else if (krvgr=="AB" and ab+a>=brjed){
        ab-ab;
        a-(brjed-ab);
        tacno++;
        q+=ab;
        y+=brjed-ab;
        cout<<"0"<<" "<<a-(brjed+ab)<<" "<<"0"<<" "<<ab<<endl;
      }
      else if (krvgr=="AB" and ab+a+b>=brjed){
        ab-ab;
        b-b;
        a-(brjed-ab-b);
        tacno++;
        q+=ab;
        z+=b;
        y+=brjed-ab-b;
        cout<<"0"<<" "<<a-(brjed+ab+b)<<" "<<b<<" "<<ab<<endl;
      }
      else if (krvgr=="AB" and ab+a+b>=brjed){
        ab-ab;
        a-a;
        b-(brjed-ab-a);
        tacno++;
        q+=ab;
        y+=a;
        z+=brjed-ab-a;
        cout<<"0"<<" "<<a<<" "<<b-(brjed+ab+a)<<" "<<ab<<endl;
      }
      else if (krvgr=="AB" and ab+a+b+o>=brjed){
        ab-ab;
        a-a;
        b-b;
        o-(brjed-ab-a-b);
        tacno++;
        q+=ab;
        z+=b;
        y+=a;
        x+=brjed-ab-a-b;
        cout<<o-(brjed+ab+a+b)<<" "<<a<<" "<<b<<" "<<ab<<endl;
      }
   }
   if (tacno==N) cout<<"moguce"<<endl;
   else cout<<"nemoguce"<<endl;
   return 0;
}