#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;

int main()
{
    ios;
    int N;
    cin>>N;
    int OZ,AZ,BZ,ABZ,O,A,B,AB;
    int M[N][4]={0};
    cin>>OZ>>AZ>>BZ>>ABZ;
    for(int i =0;i<N;i++){
        string s;
        cin>>s;
        int k;
        cin>>k;
        if(s=="A"){
            if(AZ>0){
                if(AZ>=k){
                    AZ-=k;
                    M[i][1]+=k;
                }
                else {
                    M[i][1]+=AZ;
                    k-=AZ;
                    AZ=0;
                    if(OZ>=k){
                        OZ-=k;
                        M[i][0]+=k;
                    }
                    else {
                        cout<<"nemoguce";
                        return 0;
                    }
                }
            }
            else if(OZ>=k){
                OZ-=k;
                M[i][0]+=k;
            }
            else {
                cout<<"nemoguce";
                return 0;
            }
        }
        else if(s=="O"){
            if(OZ>=k){
                M[i][0]+=k;
                OZ-=k;
            }
            else {
                cout<<"nemoguce";
                return 0;
            }
        }
        else if(s=="B"){
            if(BZ>0){
                if(BZ>=k){
                    BZ-=k;
                    M[i][2]+=k;
                }
                else {
                    M[i][2]+=BZ;
                    k-=BZ;
                    BZ=0;
                    if(OZ>=k){
                        OZ-=k;
                        M[i][0]+=k;
                    }
                    else {
                        cout<<"nemoguce";
                        return 0;
                    }
                }
            }
            else {
                cout<<"nemoguce";
                return 0;
            }
        }
        else if(s=="AB"){
            if(ABZ>=k){
                ABZ-=k;
                M[i][3]+=k;
                continue;
            }
            else if(ABZ>0){
                M[i][3]+=ABZ;
                k-=ABZ;
                ABZ=0;
            }
            if(AZ>BZ){
                if(AZ>=k){
                    M[i][1]+=k;
                    AZ-=k;
                }
                else {
                    M[i][1]+=AZ;
                    k-=AZ;
                    AZ=0;
                    if(BZ>=k){
                        M[i][2]+=BZ;
                        BZ-=k;
                    }
                    else if(BZ>0){
                        M[i][2]+=BZ;
                        k-=BZ;
                        BZ=0;
                        if(OZ>=k){
                            M[i][0]+=k;
                            OZ-=k;
                        }
                        else {
                            cout<<"nemoguce";
                            return 0;
                        }
                    }
                }
            }
            else if(BZ>AZ){
                if(BZ>=k){
                    M[i][2]+=k;
                    BZ-=k;
                }
                else {
                    M[i][2]+=BZ;
                    k-=BZ;
                    BZ=0;
                    if(AZ>=k){
                        M[i][2]+=AZ;
                        AZ-=k;
                    }
                    else if(AZ>0){
                        M[i][2]+=AZ;
                        k-=AZ;
                        AZ=0;
                        if(OZ>=k){
                            M[i][0]+=k;
                            OZ-=k;
                        }
                        else {
                            cout<<"nemoguce";
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout<<"moguce"<<endl;
    for(int i =0;i<N;i++){
        for(int j =0;j<4;j++){
            cout<<M[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}