#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
using namespace std;

const char nl='\n';
const int MOD=1000000007;
const int N=10005;

bool ok;
int n,z[6],res[6][N];
pair<string,int>p[N];

void solve(){
    ok=1;
    cin>>n>>z[1]>>z[2]>>z[3]>>z[4];
    for(int i=1;i<=n;i++){
        cin>>p[i].ff>>p[i].ss;
    }
    ///prvi prolaz O
    for(int i=1;i<=n;i++){
        if(p[i].ff=="O"){
            z[1]-=p[i].ss;
            if(z[1]<0)ok=0;
            res[1][i]=p[i].ss;
        }
    }
    for(int i=1;i<=n;i++){
        if(p[i].ff=="A"){
            int temp=min(z[2],p[i].ss);
            z[2]-=temp;
            p[i].ss-=temp;
            res[2][i]=temp;
            z[1]-=p[i].ss;
            if(z[1]<0)ok=0;
            res[1][i]=p[i].ss;
        }
        if(p[i].ff=="B"){
            int temp=min(z[3],p[i].ss);
            z[3]-=temp;
            p[i].ss-=temp;
            res[3][i]=temp;
            z[1]-=p[i].ss;
            if(z[1]<0)ok=0;
            res[1][i]=p[i].ss;
        }
    }
    for(int i=1;i<=n;i++){
        if(p[i].ff=="AB"){
            int temp=min(z[4],p[i].ss);
            z[4]-=temp;
            p[i].ss-=temp;
            res[4][i]=temp;
            temp=min(z[2],p[i].ss);
            z[2]-=temp;
            p[i].ss-=temp;
            res[2][i]=temp;
            temp=min(z[3],p[i].ss);
            z[3]-=temp;
            p[i].ss-=temp;
            res[3][i]=temp;
            z[1]-=p[i].ss;
            if(z[1]<0)ok=0;
            res[1][i]=p[i].ss;
        }
    }
    if(!ok)cout<<"nemoguce"<<nl;
    else{
       cout<<"moguce"<<nl;
       for(int i=1;i<=n;i++){
            for(int j=1;j<=4;j++){
                cout<<res[j][i]<<" ";
            }
            cout<<nl;
        }
    }
}
int main () {
cin.tie(NULL);
ios_base::sync_with_stdio(false);

int T=1;
//cin>>T;
while(T--){
    solve();
}

return 0;
}