#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define maxn 10050

using namespace std;
typedef long long ll;

int n, o, a, b, ab, zo=0, za=0, zb=0, zab=0, k, ozaa=0, ozab=0, ozaab=0, azaab=0, bzaab=0, op, ap, bp, abp;
string s;
vector<pair<string,int>> v;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> o >> a >> b >> ab;
	op=o;
	ap=a;
	bp=b;
	abp=ab;
	for(int i=0; i<n; i++)
    {
        cin >> s >> k;
        v.pb({s,k});
        if(s=="O")
        {
            zo+=k;
        }
        if(s=="A")
        {
            za+=k;
        }
        if(s=="B")
        {
            zb+=k;
        }
        if(s=="AB")
        {
            zab+=k;
        }
    }
        if(zo>o) cout << "nemoguce\n";
        else
        {
            o-=zo;
            if(za>a+o) cout << "nemoguce\n";
            else
            {
                if(a>=za) a-=za;
                else
                {
                    ozaa=za-a;
                    o=o+a-za;
                    a=0;
                }
                if(zb>b+o) cout << "nemoguce\n";
                else
                {
                    if(b>=zb) b-=zb;
                    else
                    {
                        ozab=zb-b;
                        o=o+b-zb;
                        b=0;
                    }
                    if(zab>a+b+o+ab) cout << "nemoguce\n";
                    else
                    {
                        cout << "moguce\n";
                        ozaab=o;
                        azaab=a;
                        bzaab=b;
                        o=op;
                        a=ap;
                        b=bp;
                        ab=abp;
                        for(int i=0; i<n; i++)
                        {
                            if(v[i].fi=="O") cout << v[i].se << " " << 0 << " " << 0 << " " << 0 << "\n";
                            if(v[i].fi=="A")
                            {
                                if(a>=v[i].se)
                                {
                                    cout << 0 << " " << v[i].se << " " << 0 << " " << 0 << "\n";
                                    a-=v[i].se;
                                }
                                else
                                {
                                    cout << v[i].se-a << " " << a << " " << 0 << " " << 0 << "\n";
                                    a=0;
                                }
                            }
                            if(v[i].fi=="B")
                            {
                                if(b>=v[i].se)
                                {
                                    cout << 0 << " " << 0 << " " << v[i].se << " " << 0 << "\n";
                                    b-=v[i].se;
                                }
                                else
                                {
                                    cout << v[i].se-b << " " << 0 << " " << b << " " << 0 << "\n";
                                    b=0;
                                }
                            }
                            if(v[i].fi=="AB")
                            {
                                if(ab>=v[i].se)
                                {
                                    cout << 0 << " " << 0 << " " << 0 << " " << v[i].se << "\n";
                                    ab-=v[i].se;
                                }
                                else
                                {
                                    v[i].se-=ab;
                                    if(ozaab>=v[i].se)
                                    {
                                        cout << v[i].se << " " << 0 << " " << 0 << " " << ab << "\n";
                                        ozaab-=v[i].se;
                                    }
                                    else
                                    {
                                        v[i].se-=ozaab;
                                        if(azaab>=v[i].se)
                                        {
                                            cout << ozaab << " " << v[i].se << " " << 0 << " " << ab << "\n";
                                            azaab-=v[i].se;
                                        }
                                        else
                                        {
                                            v[i].se-=azaab;
                                            cout << ozaab << " " << azaab << " " << v[i].se << " " << ab << "\n";

                                        }
                                        ozaab=0;
                                    }
                                    ab=0;
                                }
                            }
                        }

                    }
                }
            }
        }

    }