#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dec(x, y) fixed << setprecision((y)) << (x)
#define xx first
#define yy second
#define srt(v) sort((v).begin(), (v).end())
#define srtr(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define popb pop_back
#define sz(a) (int)(a).size()
#define len(a) (int)(a).length()
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n, o, a, b, ab;
pair<pii, int> niz[10002];
pair<pii, pii> res[10002];
int main() {
    ios;
    cin >> n >> o >> a >> b >> ab;
    for(int i=0; i<n; i++) {
        string s;
        cin >> s >> niz[i].xx.yy;
        if(s[0]=='O') niz[i].xx.xx=0;
        else if(s[0]=='B') niz[i].xx.xx=2;
        else if(s=="AB") niz[i].xx.xx=3;
        else niz[i].xx.xx=1;
        niz[i].yy=i;
    }
    sort(niz, niz+n);
    for(int i=0; i<n; i++) {
        if(niz[i].xx.xx==0) {
            o-=niz[i].xx.yy;
            res[i].xx.xx=niz[i].xx.yy;
            if(o<0) {
                cout << "nemoguce";
                return 0;
            }
        }
        else if(niz[i].xx.xx==1) {
            int moze=min(a, niz[i].xx.yy);
            a-=moze;
            res[i].xx.yy=moze;
            o-=niz[i].xx.yy-moze;
            res[i].xx.xx=niz[i].xx.yy-moze;
            if(o<0) {
                cout << "nemoguce";
                return 0;
            }
        }
        else if(niz[i].xx.xx==2) {
            int moze=min(b, niz[i].xx.yy);
            b-=moze;
            res[i].yy.xx=moze;
            o-=niz[i].xx.yy-moze;
            res[i].xx.xx=niz[i].xx.yy-moze;
            if(o<0) {
                cout << "nemoguce";
                return 0;
            }
        }
        else {
            int moze=min(ab, niz[i].xx.yy);
            ab-=moze;
            res[i].yy.yy=moze;
            niz[i].xx.yy-=moze;
            moze=min(a, niz[i].xx.yy);
            a-=moze;
            res[i].xx.yy=moze;
            niz[i].xx.yy-=moze;
            moze=min(b, niz[i].xx.yy);
            b-=moze;
            res[i].yy.xx=moze;
            o-=niz[i].xx.yy-moze;
            res[i].xx.xx=niz[i].xx.yy-moze;
            if(o<0) {
                cout << "nemoguce";
                return 0;
            }
        }
    }
    cout << "moguce\n";
    for(int i=0; i<n; i++) {
        cout << res[i].xx.xx << ' ' << res[i].xx.yy << ' ' << res[i].yy.xx << ' ' << res[i].yy.yy << "\n";
    }
    return 0;
}