#include <bits/stdc++.h>
using namespace std;

#define ll long long
const int N = 200001;
const int inf = 1e9 + 7;
int a[N];
string b[N];
int resenje[N][4];

void solve() {
    int n, x, y, z, d;
    int n1, n2;
    cin >> n;
    cin >> x >> y >> z >> d;
    for (int i = 0; i < n; i++) {
        cin >> b[i] >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (b[i] == "O") {
            x -= a[i];
            if (x < 0) {
                cout << "nemoguce" << endl;
                return;
            }
            resenje[i][0] = a[i];
            continue;
        }
        if (b[i] == "A") {
            int c = min(y, a[i]);
            a[i] -= c;
            y -= c;
            resenje[i][1] = c;
            c = min(x, a[i]);
            a[i] -= c;
            x -= c;
            resenje[i][0] = c;
            if (a[i] > 0) {
                cout << "nemoguce" << endl;
                return;
            }
            continue;
        }
        if (b[i] == "B") {
            int c = min(z, a[i]);
            a[i] -= c;
            z -= c;
            resenje[i][2] = c;
            c = min(x, a[i]);
            x -= c;
            a[i] -= c;
            resenje[i][0] = c;
            if (a[i] > 0) {
                cout << "nemoguce" << endl;
                return;
            }
            continue;
        }
    }
    for (int i = 0; i < n; i++) {
        if (b[i] == "AB") {
            for (int j = 0; j < 4; j++) {
                int *l;
                if (j == 0)
                    l = &x;
                if (j == 1)
                    l = &y;
                if (j == 2)
                    l = &z;
                if (j == 3)
                    l = &d;
                int c = min(*l, a[i]);
                a[i] -= c;
                *l -= c;
                resenje[i][j] = c;
            }
            if (a[i] > 0) {
                cout << "nemoguce" << endl;
                return;
            }
        }
    }
    cout << "moguce" << endl;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            cout << resenje[i][j] << " ";
        }
        cout << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}