#include <bits/stdc++.h>

using namespace std;


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, o, a, b, ab;

    cin >> n >> o >> a >> b >> ab;

    int pK[n][4] { 0 }, dK[n][4] { 0 };

    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;

        int x;
        cin >> x;

        if(s == "O") pK[i][0] = x;
        else if(s == "A") pK[i][1] = x;
        else if(s == "B") pK[i][2] = x;
        else pK[i][3] = x;
    }

    for(int i = 0; i < n; ++i){
        if(pK[i][0] > o) { cout << "nemoguce"; return 0; }
        dK[i][0] += pK[i][0], o -= pK[i][0], pK[i][0] = 0;
    }

    cout << "moguce\n";
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 4; ++j){
            cout << dK[i][j] << ' ';
        }
        cout << '\n';
    }
    return 0;
}