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

#define endl '\n'
#define ll long long
#define NMAX (int)1e6
#define vi vector<int>
#define pii pair<int,int>
#define w(x) cout<<#x<<':'<<x<<endl;
#define PB push_back
#define juseinbolt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

void nemoguce()
{
    cout<<"nemoguce";
    exit(0);
}

bool getVerdict(vector<vi> &ans, vector<vi> &input, vector<int> &zBU)
{
    //cout<<input.size()<<endl;
    for(int i=0; i<input.size(); ++i)
    {
        int tip,kol;
        for(int j=0; j<4; ++j)
        {
            if(input[i][j]!=0)
            {
                kol=input[i][j];
                tip=j;
            }
        }
        set<int> violation;
        if(tip==0) {violation.insert(1); violation.insert(2);violation.insert(3);}
        if(tip==1) {violation.insert(2); violation.insert(3);}
        if(tip==2) {violation.insert(1); violation.insert(3);}

        //cout<<endl<<tip<<";"<<kol<<endl;

        int cnt=0;
        for(int j=0; j<4; ++j)
        {
            if(violation.count(j) && ans[i][j]) return false;
            cnt+=ans[i][j];
        }
        if(cnt!=kol) return false;
    }
    for(int j=0; j<4; ++j)
    {
        int c=0;
        for(int i=0; i<input.size(); ++i)
        {
            c+=ans[i][j];
        }
        //cout<<c<<" "<<zBU[j]<<endl;
        if(c>zBU[j]) return false;
    }
    return true;
}

int main()
{
    juseinbolt;

    int n; cin>>n;
    int zA,zB,zO,zAB;
    cin>>zO>>zA>>zB>>zAB;

    vector<vector<int>> p(n,vector<int>(4,0));
    vector<vector<int>> ans(n,vector<int>(4,0));

    //vector<vector<int>> pB(n,vector<int>(4,0));
    //vector<int> zBU(4);
    //zBU[0]=zO; zBU[1]=zA; zBU[2]=zB; zBU[3]=zAB;

    for(int i=0; i<n; ++i)
    {
        string s; int x;
        cin>>s>>x;
        if(s=="O") p[i][0]+=x;
        else if(s=="A") p[i][1]+=x;
        else if(s=="B") p[i][2]+=x;
        else p[i][3]+=x;

        //for(int j=0; j<4; ++j) pB[i][j]=p[i][j];
    }
    for(int i=0; i<n; ++i)
    {
        /// popunjava O
        if(zO<p[i][0]) nemoguce();
        else
        {
            zO-=p[i][0];
            ans[i][0]+=p[i][0];
        }

        ///popunjava A, prvo sa A, onda sa O
        if(zA<p[i][1])
        {
            p[i][1]-=zA;
            ans[i][1]+=zA;
            zA=0;

            if(zO<p[i][1]) nemoguce();
            else
            {
                zO-=p[i][1];
                ans[i][0]+=p[i][1];
            }
        }
        else
        {
            zA-=p[i][1];
            ans[i][1]+=p[i][1];
        }

        /// popunjava B, prvo sa B, onda sa O
        if(zB<p[i][2])
        {
            p[i][2]-=zB;
            ans[i][2]+=zB;
            zB=0;

            if(zO<p[i][2]) nemoguce();
            else
            {
                zO-=p[i][2];
                ans[i][0]+=p[i][2];
            }
        }
        else
        {
            zB-=p[i][2];
            ans[i][2]+=p[i][2];
        }
    }

    ///popunjava AB
    for(int i=0; i<n; ++i)
    {
        int x;

        x=min(zO,p[i][3]);
        zO-=x; p[i][3]-=x;
        ans[i][0]+=x;

        x=min(zA,p[i][3]);
        zA-=x; p[i][3]-=x;
        ans[i][1]+=x;

        x=min(zB,p[i][3]);
        zB-=x; p[i][3]-=x;
        ans[i][2]+=x;

        x=min(zAB,p[i][3]);
        zAB-=x; p[i][3]-=x;
        ans[i][3]+=x;

        if(p[i][3]!=0) nemoguce();
    }

    cout<<"moguce"<<endl;
    for(int i=0; i<n; ++i)
    {
        for(int j=0; j<4; ++j) cout<<ans[i][j]<<" ";
        cout<<endl;
    }
    /*if(getVerdict(ans,pB,zBU))cout<<endl<<"OK"<<endl;
    else cout<<endl<<"WA"<<endl;*/
    return 0;
}