#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
using namespace std;

int main()
{
    int n;
    cin >> n;
    int arr[4];
    for(int i=0;i<4;i++) cin >> arr[i];

    int sols[n][4] = {0};
    string c;
    int k;
    bool solv = true;
    vector<pair<string,int>> other;
    int sa=0,sb=0,so=0,sab=0;
    for(int i = 0; i < n; i++)
    {
        cin >> c;
        cin >> k;
        other.pb(mp(c,k));

        if(c=="A") sa+=k;
        else if(c=="B") sb+=k;
        else if(c=="O") so+=k;
        else if(c=="AB") sab+=k;

    }

    if((arr[0]+arr[1]+arr[2]+arr[3]) < (sa+sb+so+sab))
    {
        solv = false;
    } else {
        for(int i = 0; i < other.size(); i++)
        {
            if(!solv) break;

            if(other[i].first == "O")
            {
                if(arr[0] >= other[i].second)
                {
                    arr[0]-=other[i].second;
                    sols[i][0]=other[i].second;
                } else {
                    solv=false;
                }
            } else if(other[i].first == "A")
            {
                if(arr[1] >= other[i].second)
                {
                    sols[i][1]=other[i].second;
                    arr[1]-=other[i].second;
                } else if((arr[1] + arr[0]) >= other[i].second)
                {
                    sols[i][1]=arr[1];
                    sols[i][0]=(other[i].second - arr[1]);
                    arr[0]-=(other[i].second - arr[1]);
                    arr[1]=0;
                } else {
                    solv=false;
                }
            } else if(other[i].first == "B")
            {
                if(arr[2] >= other[i].second)
                {
                    sols[i][2] = other[i].second;
                    arr[2]-=other[i].second;
                } else if((arr[2] + arr[0]) >= other[i].second)
                {

                    sols[i][2]=arr[2];
                    sols[i][0]=(other[i].second - arr[2]);
                    arr[0]-=(other[i].second - arr[2]);
                    arr[2]=0;
                } else {
                    solv=false;
                }
            }
        }
    }

    if(solv)
    {
        for(int i = 0; i < other.size(); i++)
        {
            if(other[i].first != "AB") continue;
            if(!solv) break;

            if(arr[3] >=  other[i].second)
            {
                sols[i][3] = other[i].second;
                arr[3]-=other[i].second;
            } else if((arr[3] + arr[0] + arr[1] + arr[2]) >= other[i].second)
            {
                int req = other[i].second - arr[3];
                sols[i][3]=arr[3];
                int ts = 0;
                for(int j = 0; j < 3; j++)
                {
                    ts+=arr[j];
                    if(ts>=req)
                    {
                        arr[j]=ts-req;
                        sols[i][j]=ts > req ? ts-req : req;
                        break;
                    }
                    sols[i][j]=arr[j];
                }

            } else {
                solv=false;
            }

        }
    }

    if(solv)
    {
        cout << "moguce" << endl;

        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < 4; j++)
            {
                cout << sols[i][j] << " ";
            }

            cout << endl;
        }
    } else {
        cout << "nemoguce";
    }

}