#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) __builtin_popcountll(a)
#define bithigh(a) 63-__builtin_clzll(a)
#define lg bithigh
ll highpow(ll a) { return 1LL << (ll)lg(a); }

using namespace std;

const ll LINF = 4e18;
const int mxN = 2e5+10, INF = 2e9, mod = (1 ? 1e9+7 : 998244353);
ll n, m;
array<int, 3> a[mxN];
array<int, 4> b, res[mxN];

bool take(int i, int k, vector<int> t){

    if (t.empty()) return 0;
    int j = t.back();
    t.pop_back();
    res[k][j] = min(a[i][1], b[j]);
    b[j] -= res[k][j];
    a[i][1] -= res[k][j];
    if (a[i][1]) return take(i, k, t);
    return 1;
}

void Solve(){

    cin >> n;
    for (int i = 0; i < 4; i++)
        cin >> b[i];
    for (int i = 0; i < n; i++){
        rs(s);
        if (s == "O") a[i][0] = 0;
        if (s == "A") a[i][0] = 1;
        if (s == "B") a[i][0] = 2;
        if (s == "AB") a[i][0] = 3;
        cin >> a[i][1];
        a[i][2] = i;
    }
    sort(a, a+n);
    for (int i = 0; i < n; i++){
        vector<int> t = {0};
        if (a[i][0] > 0) t.pb(a[i][0]);
        if (a[i][0] == 3){ t.pb(1); t.pb(2); }
        if (!take(i, a[i][2], t)){
            cout << "nemoguce" << en;
            return;
        }
    }
    cout << "moguce" << en;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 4; j++)
            cout << res[i][j] << sp;
        cout << en;
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    //cin >> t;
    while (t--)
        Solve();

    return 0;
}