#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (long long)1e18
#define MOD (long long)(1e9+7)
#define sz(x) ((int)x.size())
#define K int(12000)
#define X real()
#define Y imag()
#define F first
#define S second
#define EPS 1e-6
#define PI 3.141592
#define cross(a, b) (conj(a)*b).Y
#define MAN(a, b) norm(a-b)
#define EUC(a, b) abs(a-b)
#define PB push_back
#define REP(i, a, b) for (int i=a; i<b; i++)
#define RREP(i, a, b) for (int i=a; i>=b; i--)
#define heap priority_queue
#define endl '\n'
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned short us;
typedef complex<double> point;
typedef tree<pair<int, int> , null_type, less<pair<int, int>>, rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;

struct zahtev{
    string oz;
    int kol;
    int idx;
    bool operator<(const zahtev& x){
        if (this->oz == x.oz)
            return this->kol < x.kol;
        if (this->oz == "O") return 1;
        if (x.oz == "O") return 0;
        if (this->oz == "A") return 1;
        if (x.oz == "A") return 0;
        if (this->oz == "B") return 1;
        return 0;
    }
};

void solve(){
    int n; cin >> n;
    int O, A, B, AB;
    cin >> O >> A >> B >> AB;

    int ans[n][4] = {}, inK[n];
    zahtev in[n];
    REP(i, 0, n){
        cin >> in[i].oz >> in[i].kol;
        in[i].idx = i;
    }
    sort(in, in + n);
    int idx, tmp;
    REP(i, 0, n){
        idx = in[i].idx;

        if (in[i].oz == "A" || in[i].oz == "AB"){
            if (in[i].oz == "AB"){
                tmp = min(AB, in[i].kol);
                ans[idx][3] = tmp;
                in[i].kol -= tmp;
                AB -= tmp;
            }
            tmp = min(A, in[i].kol);
            ans[idx][1] = tmp;
            in[i].kol -= tmp;
            A -= tmp;
            if (in[i].oz == "A") in[i].oz = "O";
            else in[i].oz = "B";
        }
        if (in[i].oz == "B"){
            tmp = min(B, in[i].kol);
            ans[idx][2] = tmp;
            in[i].kol -= tmp;
            B -= tmp;
            in[i].oz = "O";
        }
        if (in[i].oz == "O"){
            tmp = min(O, in[i].kol);
            ans[idx][0] = tmp;
            in[i].kol -= tmp;
            O -= tmp;
        }
        if (in[i].kol){
            cout << "nemoguce" << endl;
            return;
        }
    }
    cout << "moguce" << endl;
    REP(i, 0, n)
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl;
}

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

    int t = 1;// cin >> t;
    REP(i, 0, t) solve();

    return 0;
}