#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
ll bz[4];
ll matra[10003][4];
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll n,i;
	cin>>n;
	vector<pair<string, ll>> lf(n);
	for(i=0;i<4;i++)
        cin>>bz[i];

    for(i=0;i<n;i++)
        cin>>lf[i].first>>lf[i].second;


        for(i=0;i<n;i++){
            if(lf[i].first=="O"){
                if(bz[0]>=lf[i].second){
                    matra[i][0]=lf[i].second;
                    matra[i][1]=0;
                    matra[i][2]=0;
                    matra[i][3]=0;
                    bz[0]-=lf[i].second;
                }
                else{
                    cout<<"nemoguce";
                    return 0;
                }
            }
        }
        for(i=0;i<n;i++){
            if(lf[i].first=="A"){
                if(bz[1]+bz[0]>=lf[i].second){
                    if(bz[1]>=lf[i].second){
                        matra[i][0]=0;
                        matra[i][1]=lf[i].second;
                        matra[i][2]=0;
                        matra[i][3]=0;
                        bz[1]-=lf[i].second;
                    }
                    else{
                        matra[i][0]=bz[0]-bz[1]-lf[i].second;
                        matra[i][1]=bz[1];
                        matra[i][2]=0;
                        matra[i][3]=0;
                        bz[0]=bz[0]-lf[i].second+bz[1];
                        bz[1]=0;
                    }
                }

                else{
                    cout<<"nemoguce";
                    return 0;
                }
            }
        }
        for(i=0;i<n;i++){
            if(lf[i].first=="B"){
                if(bz[2]+bz[0]>=lf[i].second){
                    if(bz[2]>=lf[i].second){
                        matra[i][0]=0;
                        matra[i][1]=0;
                        matra[i][2]=lf[i].second;
                        matra[i][3]=0;
                        bz[2]-=lf[i].second;
                    }
                    else{
                        matra[i][0]=lf[i].second-bz[2];
                        matra[i][1]=0;
                        matra[i][2]=bz[2];
                        matra[i][3]=0;
                        bz[0]=bz[0]-lf[i].second+bz[2];
                        bz[2]=0;
                    }
                }

                else{
                    cout<<"nemoguce";
                    return 0;
                }
            }
        }
        for(i=0;i<n;i++){
            if(lf[i].first=="AB"){
                if(bz[0]+bz[1]+bz[2]+bz[3]>=lf[i].second){
                    if(bz[0]>=lf[i].second){
                        matra[i][0]=lf[i].second;
                        matra[i][1]=0;
                        matra[i][2]=0;
                        matra[i][3]=0;
                        bz[0]-=lf[i].second;
                    }
                    else{
                        if(bz[0]+bz[1]>=lf[i].second){
                            matra[i][0]=bz[0];
                            matra[i][1]=0;
                            matra[i][2]=bz[2];
                            matra[i][3]=0;
                            bz[1]=bz[1]-lf[i].second+bz[0];
                            bz[0]=0;
                        }
                        else{
                            if(bz[0]+bz[1]+bz[2]>=lf[i].second){
                                matra[i][0]=bz[0];
                                matra[i][1]=bz[1];
                                matra[i][2]=lf[i].second-bz[0]-bz[1];
                                matra[i][3]=0;
                                bz[2]=bz[2]-(lf[i].second-bz[0]-bz[1]);
                                bz[0]=0;
                                bz[1]=0;
                            }
                                else{
                                    matra[i][0]=bz[0];
                                    matra[i][1]=bz[1];
                                    matra[i][2]=bz[2];
                                    matra[i][3]=lf[i].second-bz[0]-bz[2]-bz[1];
                                }
                        }
                    }
                }

                else{
                    cout<<"nemoguce";
                    return 0;
                }
            }
        }

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




	return 0;
}




/* rasporedim koliko mi je potrebno u O, zatim gledam koliko mi je ostalo i da li to mogu da rasporedim u
A i B, i na kraju gledam sta mi je ostalo i to stavim u AB
5
5 7 3 1
O 2
A 3
B 1
AB 4
O 3
*/