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

using ll = long long;
using ld = long double;

const int N = 100000;

vector <int> vec[4];
int soln[N+5][4];
int needs[N+5];
int cnt[4];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    for(int i=0; i<4; i++) cin >> cnt[i];
    for(int i=1; i<=n; i++){
        string c;
        cin >> c;
        if(c == "O") vec[0].push_back(i);
        else if(c == "A") vec[1].push_back(i);
        else if(c == "B") vec[2].push_back(i);
        else vec[3].push_back(i);
        cin >> needs[i];
    }
    for(int j=0; j<4; j++){
        for(auto i : vec[j]){
            for(int k=0; k<4; k++){
                if((k & j) != k) continue;
                if(cnt[k] >= needs[i]) soln[i][k] += needs[i], cnt[k] -= needs[i], needs[i] = 0;
                else soln[i][k] += cnt[k], needs[i] -= cnt[k], cnt[k] = 0;
            }
            if(needs[i]){
                cout << "nemoguce\n";
                return 0;
            }
        }
    }
    cout << "moguce\n";
    for(int i=1; i<=n; i++){
        for(int j=0; j<4; j++){
            cout << soln[i][j] << " ";
        }
        cout << "\n";
    }
    return 0;
}