#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define sc second
#define th third
#define fo fourth
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
#define endl "\n"
#define MAXN 10007
int o[MAXN],a[MAXN],b[MAXN],ab[MAXN];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    int bro,bra,brb,brab;
    cin>>bro>>bra>>brb>>brab;
    string s[n];
    int cnt[n];
    for(int i=0;i<n;i++) cin>>s[i]>>cnt[i];
    int rez=1;
    for(int i=0;i<n;i++)
    {
        if(s[i]=="O")
        {
            bro-=cnt[i];
            o[i]=cnt[i];
        }
        if(bro<0)
        {
            rez=0;
            break;
        }
    }
    if(rez==0) cout<<"nemoguce"<<endl;
    else
    {
        for(int i=0;i<n;i++)
        {
            if(s[i]=="A")
            {
                int x=bra,y=cnt[i];
                cnt[i]-=min(x,y);
                a[i]=min(x,y);
                bra-=min(x,y);
                if(cnt[i]!=0)
                {
                    o[i]=cnt[i];
                    bro-=cnt[i];
                }
            }
            else if(s[i]=="B")
            {
                int x1=brb,y1=cnt[i];
                cnt[i]-=min(x1,y1);
                b[i]=min(x1,y1);
                brb-=min(x1,y1);
                if(cnt[i]!=0)
                {
                    o[i]=cnt[i];
                    bro-=cnt[i];
                }
            }
            if(bro<0)
            {
                rez=0;
                break;
            }
        }
        if(rez==0) cout<<"nemoguce"<<endl;
        else
        {
            for(int i=0;i<n;i++)
            {
                if(s[i]=="AB")
                {
                    int x2=brab,y2=cnt[i];
                    cnt[i]-=min(x2,y2);
                    ab[i]=min(x2,y2);
                    brab-=min(x2,y2);
                    if(cnt[i]!=0)
                    {
                        int x3=bra,y3=cnt[i];
                        cnt[i]-=min(x3,y3);
                        a[i]=min(x3,y3);
                        bra-=min(x3,y3);
                        if(cnt[i]!=0)
                        {
                            int x4=brb,y4=cnt[i];
                            cnt[i]-=min(x4,y4);
                            b[i]=min(x4,y4);
                            brb-=min(x4,y4);
                            if(cnt[i]!=0)
                            {
                                o[i]=cnt[i];
                                bro-=cnt[i];
                            }
                        }
                    }
                }
                if(bro<0)
                {
                    rez=0;
                    break;
                }
            }
            if(rez==0) cout<<"nemoguce";
            else
            {
                cout<<"moguce"<<endl;
                for(int i=0;i<n;i++)
                {
                    cout<<o[i]<<" "<<a[i]<<" "<<b[i]<<" "<<ab[i]<<endl;
                }
            }
        }
    }
    return 0;
}