#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

const int mxN = 1e5+5;
const int mod = 1e9+7;
const int mxlogN = 20;
const int mxK = 52;

int ans[4][mxN];
bool isAB[mxN];
int a[mxN];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    int O, A, B, AB; cin >> O >> A >> B >> AB;
    bool ok = 1;
    int req = 0;
    for(int i = 0; i < n; i++)
    {
        string s; cin >> s >> a[i];
        int x = a[i];
        if(s=="O")
        {
            if(O < x) ok = 0;
            else
            {
                ans[0][i] = x;
                O -= x;
            }
        }
        else if(s=="A")
        {
            int mn = min(x, A);
            x -= mn;
            A -= mn;
            ans[1][i] = mn;
            if(O < x) ok = 0;
            else
            {
                ans[0][i] = x;
                O -= x;
            }
        }
        else if(s=="B")
        {
            int mn = min(x, B);
            x -= mn;
            B -= mn;
            ans[2][i] = mn;
            if(O < x) ok = 0;
            else
            {
                ans[0][i] = x;
                O -= x;
            }
        }
        else
        {
            req += x;
            isAB[i] = 1;
        }
    }
    if(!ok || req>O+A+B+AB)
    {
        cout << "nemoguce\n";
        return 0;
    }
    cout << "moguce\n";
    for(int i = 0; i < n; i++)
    {
        if(isAB[i])
        {
            int mn;
            mn = min(a[i], O), O -= mn, a[i] -= mn, ans[0][i] = mn;
            mn = min(a[i], A), A -= mn, a[i] -= mn, ans[1][i] = mn;
            mn = min(a[i], B), B -= mn, a[i] -= mn, ans[2][i] = mn;
            mn = min(a[i], AB), AB -= mn, a[i] -= mn, ans[3][i] = mn;
        }
        for(int j = 0; j < 4; j++) cout << ans[j][i] << " ";
        cout << "\n";
    }
}