#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,j;
    int zpgo = 0,zpga = 0,zpgb = 0,zpgab = 0;/*zpa -potreba pacienta sa grupom ...*/
    cin >> n;
    int O, A, B , AB;  /*ZALIHE BOLNICE*/
    cin >> O >> A >> B >> AB;
    int op[n], ap[n], bp[n], abp[n], kjg[n];/*kjg koja je grupa*/
    char c;

    for(int i = 0; i < n;i++){
        cin >> c >> j;
        if( c=='O'){
        op[i]=j; ap[i] = 0;bp[i] = 0;abp[i] = 0;
         zpgo+=j; kjg[i] = 1; }
        if(c == 'A'){
        ap[i] = j;op[i] = 0;bp[i] = 0;abp[i] = 0;
         zpga+=j; kjg[i] = 2;}
        if(c == 'B'){
        bp[i] = j;op[i] = 0;ap[i] = 0;abp[i] = 0;
         zpgb+=j; kjg[i] = 3;}
        }
        int ogo, oga, ogb;  /*ostatak grupe ...*/
         if(zpgo > O)/* mora da se menja*/
            cout << "nemoguce";
        else if(zpgo <= O)
        if(zpga > A && zpgb > B){
            ogo = O-zpgo;oga = zpga - A;ogb =zpgb - B;
            if(oga + ogb > ogo)
            cout << "nemoguce";}
         else{
            cout << "moguce"<< endl;
            for(int i = 0; i < n;i++){
            if(kjg[i] == 1){
                cout << op[i] << " "<<ap[i] << " "<< bp[i]<< " "<< abp[i] << endl; O-=op[i];}
            if(kjg[i] == 2){
                 if(A < ap[i]){
                op[i] = ap[i] - A;
                cout << op[i] << " "<< A << " "<< bp[i] << " " << abp[i]<<endl;

                A = 0; O-=ap[i]-A;}
                else{
                cout << op[i] << " "<<ap[i] << " "<< bp[i]<< " "<< abp[i] << endl;
                    A -= ap[i];}}
            if(kjg[i] == 3){
               if(B < ap[i]){
                op[i] = bp[i] - B;
                cout << op[i] << " "<< ap[i] << " "<< B << " " << abp[i]<<endl;

                B = 0; O-=ap[i]-B;}
                else{
                cout << op[i] << " "<< ap[i] << " "<< bp[i]<< " "<< abp[i] << endl;
                    B-= bp[i];}}
            }



         }
    return 0;
}