#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,res,pom;
    bool change=true;
    int a,b,ab,o;
    cin>>n;
    int m[n][4];
    for(int i=0;i<n;i++)
        for(int j=0;j<4;j++) m[i][j]=0;
    cin >> o >> a >> b >> ab;
    pair<string,int>p[n];
    for(int i=0;i<n;i++)cin>>p[i].first>>p[i].second;
    for(int i=0;i<n;i++){
        if(p[i].first=="O")
        {
            res=0;
            if(o<p[i].second) {
            cout<<"nemoguce"<<'\n',change=false;
            break;
            }
            else o-=p[i].second,m[i][0]=p[i].second;

        }
        else  if(p[i].first=="A")
        {
            res=0;
            if(a<p[i].second){
                res=p[i].second-a,m[i][1]=a;
                if(o<res){
                    cout<<"nemoguce"<<'\n',change=false;
                    break;
                }
                else o-=res,a-=p[i].second-res,m[i][0]=p[i].second-a;

            }
            else m[i][1]=p[i].second,a-=p[i].second;
        }
        else  if(p[i].first=="B")
        {
            res=0;
            if(b<p[i].second){
                res=p[i].second-b,m[i][2]=b;
                if(o<res){
                    cout<<"nemoguce"<<'\n',change=false;
                    break;
                }
                else o-=res,b-=p[i].second-res,m[i][2]=p[i].second-b;

            }
            else m[i][2]=p[i].second,b-=p[i].second;
        }
        else
        {
            res=0;
            if(ab<p[i].second){
                res=p[i].second-ab,m[i][3]=ab,ab=0;
                if(a<res){
                   res=res-a,m[i][1]=a,a=0;
                   if(b<res){
                     res=res-b,m[i][2]=b,b=0;
                       if(o<res){
                       cout<<"nemoguce"<<'\n',change=false;
                        break;
                       }
                       else m[i][0]=res,o-=res;
                    }
                    else m[i][0]=res,b-=res;
                 }
                 else m[i][1]=res,a-=p[i].second;
             }
            else m[i][3]=p[i].second,ab-=p[i].second;
        }
    }
    if(change){
     cout<<"moguce"<<'\n';
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++) cout << m[i][j] <<" ";
        cout<<'\n';
      }
    }
    return 0;
}