#include <bits/stdc++.h>
//#include <string>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    long long br, x;
    cin>>br;
    short f = 1;
    long long niz[4];
    cin>>niz[0]>>niz[1]>>niz[2]>>niz[3];
    string a;
    int p = 0;
    pair<pair<string, long long>, int> upiti[br];
    int mat[br][4];

    for(int i = 0; i < br && f; i++)
    {
        cin>>a;
        cin>>x;
        mat[i][0] = 0;
        mat[i][1] = 0;
        mat[i][2] = 0;
        mat[i][3] = 0;
        if(a == "O")
        {
            if(niz[0] >= x)
            {
                mat[i][0] = x;
                niz[0] -= x;
            }
            else
            {
                f = 0;
            }
        }
        else if(a == "A")
        {
            if(niz[1] >= x)
            {
                mat[i][1] = x;
                niz[1] -= x;
            }
            else
            {
                x-=niz[1];
                mat[i][1] = niz[1];
                niz[1] = 0;
                if(niz[0] >= upiti[i].second)
                {
                    mat[i][0] = x;
                    niz[0] -= x;
                }
                else
                {
                    f = 0;
                }

            }
        }
        else if(a == "B")
        {
            if(niz[2] >= x)
            {
                mat[i][2] = x;
                niz[2] -= x;
            }
            else
            {
                x-=niz[2];
                mat[i][2] = niz[2];
                niz[2] = 0;
                if(niz[0] >= x)
                {
                    mat[i][0] = x;
                    niz[0] -= x;
                }
                else
                {
                    f = 0;
                }

            }

        }
        else
        {
            upiti[p].first.first = a;
            upiti[p].first.second = x;
            upiti[p].second = i;
            p++;
        }
    }
    int i, p1 = p-1;
    for(int p = 0; p <= p1 && f; p++)
    {
        //cout<<p;
        //cout<<upiti[p].first.first<<" "<<upiti[p].first.second;
        if(upiti[p].first.first == "AB")
        {
            i = upiti[p].second;
            if(niz[3] >= upiti[p].first.second)
            {
                mat[i][3] = upiti[p].first.second;
                niz[3] -= upiti[p].first.second;
            }
            else
            {
                upiti[p].first.second-=niz[3];
                mat[i][3] = niz[3];
                niz[3] = 0;
                if(niz[1] >= upiti[p].first.second)
                {
                    mat[i][1] = upiti[p].first.second;
                    niz[1] -= upiti[p].first.second;
                }
                else
                {
                    upiti[p].first.second-=niz[1];
                    mat[i][1] = niz[1];
                    niz[1] = 0;
                    if(niz[2] >= upiti[p].first.second)
                    {
                        mat[i][2] = upiti[p].first.second;
                        niz[2] -= upiti[p].first.second;
                    }
                    else
                    {
                        upiti[p].first.second-=niz[2];
                        mat[i][2] = niz[2];
                        niz[2] = 0;
                        if(niz[0] >= upiti[p].first.second)
                        {
                            mat[i][0] = upiti[p].first.second;
                            niz[0] -= upiti[p].first.second;
                        }
                        else
                        {
                            f = 0;
                        }
                    }
                }

            }
            p++;
        }
    }

    if(f == 0)
    {
        cout<<"nemoguce";
    }
    else
    {
        for(int i = 0; i < br; i++)
        {
            cout<<mat[i][0]<<" "<<mat[i][1]<<" "<<mat[i][2]<<" "<<mat[i][3]<<"\n";
        }
    }



}