#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
const int N = 2e5 + 5;
const ll mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> cnt(4);
    for (int i = 0; i < 4; i++) cin >> cnt[i];
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        string zzz;
        cin >> zzz;
        if (zzz == "O") a[i].first = 0;
        if (zzz == "A") a[i].first = 1;
        if (zzz == "B") a[i].first = 2;
        if (zzz == "AB") a[i].first = 3;
        cin >> a[i].second;
    }
    vector<vector<int>> ans(n, vector<int>(4));
    for (int i = 0; i < n; i++) {
        if (a[i].first != 0) continue;
        if (a[i].second > cnt[0]) {
            cout << "nemoguce" << en;
            return 0;
        }
        ans[i][0] = a[i].second;
        cnt[0] -= a[i].second;
    }
    for (int i = 0; i < n; i++) {
        if (a[i].first != 1) continue;
        if (a[i].second <= cnt[1]) {
            ans[i][1] = a[i].second;
            cnt[1] -= a[i].second;
            continue;
        }
        ans[i][1] = cnt[1];
        a[i].second -= cnt[1];
        cnt[1] = 0;
        if (a[i].second > cnt[0]) {
            cout << "nemoguce" << en;
            return 0;
        }
        ans[i][0] = a[i].second;
        cnt[0] -= a[i].second;
    }
    for (int i = 0; i < n; i++) {
        if (a[i].first != 2) continue;
        if (a[i].second <= cnt[2]) {
            ans[i][2] = a[i].second;
            cnt[2] -= a[i].second;
            continue;
        }
        ans[i][2] = cnt[2];
        a[i].second -= cnt[2];
        cnt[2] = 0;
        if (a[i].second > cnt[0]) {
            cout << "nemoguce" << en;
            return 0;
        }
        ans[i][0] = a[i].second;
        cnt[0] -= a[i].second;
    }
    for (int i = 0; i < n; i++) {
        if (a[i].first != 3) continue;
        int sum = 0;
        for (int j = 0; j < 4; j++) {
            int mn = min(a[i].second, cnt[j]);
            a[i].second -= mn;
            cnt[j] -= mn;
            ans[i][j] = mn;
            sum += mn;
        }
        if (sum < a[i].second) {
            cout << "nemoguce" << en;
            return 0;
        }
    }
    cout << "moguce" << en;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            cout << ans[i][j] << sp;
        }
        cout << en;
    }
    return 0;

}