#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,zo,zab,za,zb,i,m;
    scanf("%d",&n);
    int p[n],a[n],b[n],ab[n],o[n],abi[n];
    string t;
    scanf("%d %d %d %d",&zo,&za,&zb,&zab);
    m=0;
    for(i=0;i<n;i++)
    {
        cin>>t>>p[i];
        if(zo<0)
        {
            continue;
        }
        if(t=="AB")
        {
            abi[m]=i;
            m++;
        }
        if(t=="O")
        {
            zo-=p[i];
            a[i]=0;
            b[i]=0;
            ab[i]=0;
            o[i]=p[i];
        }
        if(t=="A")
        {
            za-=p[i];
            o[i]=0;
            b[i]=0;
            ab[i]=0;
            a[i]=p[i];
            if(za<0)
            {
                zo+=za;
                o[i]=-za;
                a[i]+=za;
                za=0;
            }
        }
        if(t=="B")
        {
            zb-=p[i];
            o[i]=0;
            a[i]=0;
            ab[i]=0;
            b[i]=p[i];
            if(zb<0)
            {
                zo+=zb;
                o[i]=-zb;
                b[i]+=zb;
                zb=0;
            }
        }
    }
    if(zo<0)
    {
        printf("nemoguce");
        return 0;
    }
    for(i=0;i<m;i++)
    {
        zab-=p[abi[i]];
        o[abi[i]]=0;
        b[abi[i]]=0;
        a[abi[i]]=0;
        ab[abi[i]]=p[abi[i]];
        if(zab<0)
        {
            za+=zab;
            a[abi[i]]=-zab;
            ab[abi[i]]+=zab;
            zab=0;
        }
        if(za<0)
        {
            zb+=za;
            b[abi[i]]=-za;
            a[abi[i]]+=za;
            za=0;
        }
        if(zb<0)
        {
            zo+=zb;
            o[abi[i]]=-zb;
            b[abi[i]]+=zb;
            zb=0;
        }
    }
    if(zo<0)
    {
        printf("nemoguce");
        return 0;
    }
    printf("moguce\n",abi[0]);
    for(i=0;i<n;i++)
    {
        printf("%d %d %d %d\n",o[i],a[i],b[i],ab[i]);
    }
    return 0;
}