#include <bits/stdc++.h>

#define xx first
#define yy second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair
#define pb push_back
#define popb pop_back

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef string str;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX=1e5+3;
ll n, o, a, b, ab, om, am, bm, abm;
pll x[MAX];
ll p[MAX][5];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n;
    cin >> o >> a >> b >> ab;
    for(ll i=0;i<n;++i){
        string k;
        cin >> k >> x[i].yy;
        if(k=="O"){x[i].xx=0; om+=x[i].yy;}
        if(k=="A"){x[i].xx=1; am+=x[i].yy;}
        if(k=="B"){x[i].xx=2; bm+=x[i].yy;}
        if(k=="AB"){x[i].xx=3; abm+=x[i].yy;}
    }
    if(om>o) return cout << "nemoguce\n", 0;
    for(ll i=0;i<n;++i){
        if(x[i].xx==0){
            p[i][0]=x[i].yy;
            o-=x[i].yy;
            continue;
        }
    }
    if(o+a<am) return cout << "nemoguce\n", 0;
    for(ll i=0;i<n;++i){
        if(x[i].xx!=1) continue;
        if(a>=x[i].yy){
            p[i][1]=x[i].yy;
            a-=x[i].yy;
            continue;
        }
        if(a>0 && a<x[i].yy){
            p[i][1]=a;
            p[i][0]=x[i].yy-a;
            o-=(x[i].yy-a);
            a=0;
            continue;
        }
        if(a==0){
            p[i][0]=x[i].yy;
            o-=x[i].yy;
            continue;
        }
    }
    if(o+b<bm) return cout << "nemoguce\n", 0;
    for(ll i=0;i<n;++i){
        if(x[i].xx!=2) continue;
        if(b>=x[i].yy){
            p[i][2]=x[i].yy;
            b-=x[i].yy;
            continue;
        }
        if(b>0 && b<x[i].yy){
            p[i][2]=b;
            p[i][0]=x[i].yy-b;
            o-=(x[i].yy-b);
            b=0;
            continue;
        }
        if(b==0){
            p[i][0]=x[i].yy;
            o-=x[i].yy;
            continue;
        }
    }
    if(o+a+b+ab<abm) return cout << "nemoguce\n", 0;
    for(ll i=0;i<n;++i){
        if(x[i].xx!=3) continue;
        if(ab>=x[i].yy){
            p[i][3]=x[i].yy;
            ab-=x[i].yy;
            continue;
        }
        if(a>x[i].yy){
            p[i][1]=x[i].yy;
            a-=x[i].yy;
            continue;
        }
        if(b>=x[i].yy){
            p[i][2]=x[i].yy;
            b-=x[i].yy;
            continue;
        }
        if(o>=x[i].yy){
            p[i][0]=x[i].yy;
            o-=x[i].yy;
            continue;
        }
        ll col=x[i].yy;
        if(o+a>col){
            p[i][0]=o;
            col-=o;
            o=0;
            p[i][1]=col;
            a-=col;
            continue;
        }
        if(o+a+b>col){
            p[i][0]=o;
            col-=o;
            o=0;
            p[i][1]=a;
            col-=a;
            a=0;
            p[i][2]=col;
            b-=col;
            continue;
        }
        if(o+a+b+ab>col){
            p[i][0]=o;
            col-=o;
            o=0;
            p[i][1]=a;
            col-=a;
            a=0;
            p[i][2]=b;
            col-=b;
            b=0;
            p[i][3]=col;
            ab-=col;
            continue;
        }
    }
    cout << "moguce\n";
    for(ll i=0;i<n;++i){
        for(ll j=0;j<4;++j) cout << p[i][j] << ' ';
        cout << '\n';
    }
    return 0;
}
/**
7
9 3 4 5
O 3
A 5
B 2
O 1
AB 1
B 4
AB 1
**/