#define here cerr<<"---------------------------\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
using namespace std;
#define maxn 10005
ll n;
ll cnt[4];
ll b[maxn];
ll a[maxn];
map<string,ll> mp;
vector<ll> v[maxn];
ll ans[maxn][4];
#define ne cout<<"nemoguce"<<endl
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	mp["O"] = 0;
	mp["A"] = 1;
	mp["B"] = 2;
	mp["AB"] = 3;
    cin >> n;
    for(ll i = 0;i<4;i++) cin >> cnt[i];
    //O A B AB
    for(ll i = 1;i<=n;i++){
        string s; cin >> s;
        b[i] = mp[s];
        cin >> a[i];
        v[b[i]].pb(i);
    }
    for(ll x : v[0]){
        if(cnt[0]<a[x]){
            ne;
        }
        cnt[0]-=a[x];
        ans[x][0]+=a[x];
        a[x] = 0;
    }
    for(ll x : v[1]){
        if(cnt[1]<a[x]){
            ans[x][1]+=cnt[1];
            a[x]-=cnt[1];
            cnt[1] = 0;
            if(cnt[0]<a[x]){
                ne;
            }
            cnt[0]-=a[x];
            ans[x][0]+=a[x];
            a[x] = 0;
        }else{
            ans[x][1]+=a[x];
            cnt[1]-=a[x];
            a[x] = 0;
        }
    }
    for(ll x : v[2]){
        if(cnt[2]<a[x]){
            ans[x][2]+=cnt[2];
            a[x]-=cnt[2];
            cnt[2] = 0;
            if(cnt[0]<a[x]){
                ne;
            }
            cnt[0]-=a[x];
            ans[x][0]+=a[x];
            a[x] = 0;
        }else{
            ans[x][2]+=a[x];
            cnt[2]-=a[x];
            a[x] = 0;
        }
    }
    for(ll x : v[3]){
        for(ll j = 0;j<4;j++){
            if(a[x]==0) break;
            if(cnt[j]>=a[x]){
                ans[x][j]+=a[x];
                a[x] = 0;
                cnt[j]-=a[x];
            }else{
                ans[x][j]+=cnt[j];  
                a[x]-=cnt[j];
                cnt[j] = 0;
            }
        }
    }
    for(ll i = 1;i<=n;i++){
        if(a[i]>0){
            ne;
            return 0;
        }
    }
    cout<<"moguce"<<endl;
    for(ll i = 1;i<=n;i++){
        for(ll j = 0;j<4;j++) cout<<ans[i][j]<< " ";
        cout<<endl;
    }
	return 0;
}