#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) begin(a),end(a)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ld, null_type,less<ld>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key -> # less than k
// find_by_order -> k-th element
// pq max element

const double eps = 0.000001;
const int modi = 1e9+7;
const int NMAX = 200010;
string tip[NMAX];
int koliko[NMAX];
int res[NMAX][4];
void solve() {
    int n;
    cin >> n;
    int o, a, b, ab;
    cin >> o >> a >> b >> ab;
    int u = 0;
    for (int i = 0 ; i < n ; i++ ) {
        cin >> tip[i] >> koliko[i];
        u += koliko[i];
    }
    if ( o + a + b + ab < u ) {
        puts("nemoguce");
        return;
    }

    for (int i = 0 ; i < n ; i++ ) {
        if ( tip[i] == "O" ) {
            if ( o < koliko[i] ) {
                puts("nemoguce");
                return;
            }
            o-=koliko[i];
            res[i][0] += koliko[i];
        }
        else if ( tip[i] == "A" ) {
            int t = min(koliko[i], a);
            res[i][1] += t;
            koliko[i] -= t;
            a -= t;
            if ( o < koliko[i] ) {
                puts("nemoguce");
                return;
            }
            o-=koliko[i];
            res[i][0] += koliko[i];
        }
        else if ( tip[i] == "B" ) {
            int t = min(koliko[i], b);
            res[i][2] += t;
            koliko[i] -= t;
            b -= t;
            if ( o < koliko[i] ) {
                puts("nemoguce");
                return;
            }
            o-=koliko[i];
            res[i][0] += koliko[i];
        }
        else continue;
        koliko[i] = 0;
    }

    for (int i = 0 ; i < n ; i++ ) {
        if ( tip[i] == "AB" ) {
            int t = min(o, koliko[i]);
            res[i][0] += t;
            koliko[i] -= t;

            t = min(a, koliko[i]);
            res[i][1] += t;
            koliko[i] -= t;

            t = min(b, koliko[i]);
            res[i][2] += t;
            koliko[i] -= t;

            t = min(ab, koliko[i]);
            res[i][3] += t;
            koliko[i] -= t;
        }
    }
    cout << "moguce\n";
    for (int i = 0 ; i < n ; i++ ) {
        for (int j = 0 ; j < 4 ; j++ ) {
            cout << res[i][j] << ' ';
        }
        cout << endl ;
    }

}


int main () {
    


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

    int t = 1;
    
    //cin >>t ; 


    int i = 1 ;
    while(t--) {
        //cout << "Case #" << i++ << ": " ;
        solve(); 
    }
}