#include <iostream>

using namespace std;

int main()
{
    int N,o,a,b,ab,x,y,z,t;
    int jedinica[N];
    string krvnagrupa[N],O,A,B,AB;
    cin>>N;
    cin>>o>>a>>b>>ab;
    x=0;
    y=0;
    z=0;
    t=0;

    for(int i=1;i<=N;i++)
        {

            cin>>krvnagrupa[i]>>jedinica[i];
            if (krvnagrupa[i]=="O")
                x=x+jedinica[i];
            if (krvnagrupa[i]=="A")
                y=y+jedinica[i];
            if (krvnagrupa[i]=="B")
                z=z+jedinica[i];
            if (krvnagrupa[i]=="AB")
                t=t+jedinica[i];
        }
    if(x>o)
        cout<<"nemoguce"<<endl;
    else{
        if(y>a+(o-x))
            cout<<"nemoguce"<<endl;
        else{
            if(z>b+(o-x-y+a))
                cout<<"nemoguce"<<endl;
            else{
                if(t>ab+(o-x-y+a-z+b))
                    cout<<"nemoguce"<<endl;
                else
                    cout<<"moguce"<<endl;
    for (int j=1;j<=N;j++)
        {
            if(krvnagrupa[j]=="O" && jedinica[j]<=o){
                cout<<jedinica[j]<<" "<<0<<" "<<0<<" "<<0<<endl;
                o=o-jedinica[j];}
            else
                if(krvnagrupa[j]=="A" && jedinica[j]<=a){
                    cout<<0<<" "<<jedinica[j]<<" "<<0<<" "<<0<<endl;
                    a=a-jedinica[j];}
                else
                    if(krvnagrupa[j]=="A"){
                        cout<<jedinica[j]-a<<" "<<a<<" "<<0<<" "<<0<<endl;
                        o=o-jedinica[j]+a;
                        a=0;}
                    else
                        if(krvnagrupa[j]=="B" && jedinica[j]<=b){
                            cout<<0<<" "<<0<<" "<<jedinica[j]<<" "<<0<<endl;
                            b=b-jedinica[j];}
                        else
                            if(krvnagrupa[j]=="B"){
                                cout<<jedinica[j]-b<<" "<<0<<" "<<b<<" "<<0<<endl;
                                o=o-jedinica[j]+b;
                                b=0;}
                            else
                                if(jedinica[j]<=ab){
                                    cout<<0<<" "<<0<<" "<<0<<" "<<jedinica[j]<<endl;
                                    ab=ab-jedinica[j];}
                                else
                                    if(o+ab>=jedinica[j]){
                                        cout<<jedinica[j]-ab<<" "<<0<<" "<<0<<" "<<ab<<endl;
                                        o=o-jedinica[j]+ab;
                                        ab=0;}
                                    else
                                        if(o+ab+a>=jedinica[j]){
                                            cout<<o<<" "<<jedinica[j]-ab-o<<" "<<0<<" "<<ab<<endl;
                                            o=0;
                                            ab=0;
                                            a=a-jedinica[j]+ab+o;}
                                         else
                                            if(o+ab+b>=jedinica[j]){
                                                cout<<o<<" "<<0<<" "<<jedinica[j]-ab-o<<" "<<ab<<endl;
                                                o=0;
                                                ab=0;
                                                b=b-jedinica[j]+ab+o;}
                                            else
                                                if(o+ab+a<jedinica[j]){
                                                    cout<<o<<" "<<a<<" "<<jedinica[j]-ab-o-a<<" "<<ab<<endl;
                                                    o=0;
                                                    ab=0;
                                                    a=0;
                                                    b=b-jedinica[j]+ab+o+a;}
                                                else
                                                    if(o+ab+b<jedinica[j]){
                                                        cout<<o<<" "<<jedinica[j]-ab-o-b<<" "<<b<<" "<<ab<<endl;
                                                        o=0;
                                                        b=0;
                                                        ab=0;
                                                        a=a-jedinica[j]+ab+o+b;}
            }
        }
            }
        }
}