#include <bits/stdc++.h>
#define ll long long
#define MAXN 10010
using namespace std;
struct jedinice
{
    ll bro=0;
    ll bra=0;
    ll brb=0;
    ll brab=0;
};
jedinice r[MAXN];
ll t[MAXN];
string g[MAXN];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,o,a,b,ab,po=0,pa=0,pb=0,pab=0;
    bool moze=true;
    cin >> n >> o >> a >> b >> ab;
    for (ll i=1;i<=n;i++)
    {
        cin >> g[i];
        cin >> t[i];
        if (g[i]=="O")
            po+=t[i];
        if (g[i]=="A")
            pa+=t[i];
        if (g[i]=="B")
            pb+=t[i];
        if (g[i]=="AB")
            pab+=t[i];
    }
    ll sa=0,sb=0,so=0;
    if (o<po)
    {
        cout << "nemoguce\n";
        return 0;
    }
    so=o-po;
    if (a>pa)
        sa=a-pa;
    if (b>pb)
        sb=b-pb;
    for (ll i=1;i<=n;i++)
    {
        if (g[i]=="O")
        {
            r[i].bro=t[i];
            continue;
        }
        if (g[i]=="A")
        {
            if (a>=t[i])
            {
                r[i].bra=t[i];
                a-=t[i];
                continue;
            }
            r[i].bra=a;
            t[i]-=a;
            a=0;
            if (so<t[i])
            {
                cout << "nemoguce\n";
                return 0;
            }
            r[i].bro=t[i];
            so-=t[i];
            continue;
        }
        if (g[i]=="B")
        {
            if (b>=t[i])
            {
                r[i].brb=t[i];
                b-=t[i];
                continue;
            }
            r[i].brb=b;
            t[i]-=b;
            b=0;
            if (so<t[i])
            {
                cout << "nemoguce\n";
                return 0;
            }
            r[i].bro=t[i];
            so-=t[i];
            continue;
        }
        if (ab>=t[i])
        {
            r[i].brab=t[i];
            ab-=t[i];
            continue;
        }
        r[i].brab=ab;
        t[i]-=ab;
        ab=0;
        if (sa>=t[i])
        {
            sa-=t[i];
            r[i].bra=t[i];
            continue;
        }
        r[i].bra=sa;
        t[i]-=sa;
        sa=0;
        if (sb>=t[i])
        {
            sb-=t[i];
            r[i].brb=t[i];
            continue;
        }
        r[i].brb=sb;
        t[i]-=sb;
        sb=0;
        if (so<t[i])
        {
            cout << "nemoguce\n";
            return 0;
        }
        so-=t[i];
        r[i].bro=t[i];
    }
    cout << "moguce\n";
    for (ll i=1;i<=n;i++)
        cout << r[i].bro << " " << r[i].bra << " " << r[i].brb << " " << r[i].brab << "\n";
    return 0;
}