#include <bits/stdc++.h>
using namespace std;
int n,o,a,b,ab,br;
string c;
bool resenje = true;
struct slog {
    int o1,a1,b1,ab1;
}res[1000005];
int main() {
    cin >> n >> o >> a >> b >> ab;
    for( int i=1;i<=n;i++ ){
        cin >> c >> br;

        if(c == "O" and o>=br ) {
            o-=br;
            res[i].o1 += br;
            resenje = false;
        }

        if( c == "A" and a+o>=br ){
            if( a - br >= 0 ) {a-=br;res[i].a1+=br;}
            else {
                res[i].a1 = a;br-=a;a=0;
                res[i].o1+=br;o-=br;
            }
            resenje = false;
        }
        if( c == "B" and b+o>=br ){
            if( b - br >= 0 ) {b-=br;res[i].b1+=br;}
            else {
                res[i].b1 = b;br-=b;b=0;
                res[i].o1+=br;o-=br;
            }
            resenje = false;
        }
        if(c =="AB" and a+b+o+ab>=br){
            if( ab >= br ) { res[i].ab1+=br;ab-=br; }
            else if( ab+a>=br ){
                res[i].ab1+=ab;br-=ab;ab=0;
                res[i].a1+=br;a-=br;
            }
            else if( ab+b>=br){
                res[i].ab1+=ab;br-=ab;ab=0;
                res[i].b1+=br;b-=br;
            }
            else if( ab+o>=br ){
                res[i].ab1+=ab;br-=ab;ab=0;
                res[i].o1+=br;o-=br;
            }
            else if(ab+a+b>=br){
                res[i].ab1+=ab;br-=ab;ab=0;
                res[i].a1+=a;br-=a;a=0;
                res[i].b1+=br;b-=br;
            }
            else if(ab+o+b>=br){
                res[i].ab1+=ab;br-=ab;ab=0;
                res[i].o1+=o;br-=o;o=0;
                res[i].b1+=br;b-=br;
            }
            else if(ab+o+a>=br){
                res[i].ab1+=ab;br-=ab;ab=0;
                res[i].o1+=o;br-=o;o=0;
                res[i].a1+=br;a-=br;
            }
            else if(ab+a+b+o>=br){
                res[i].ab1+=ab;br-=ab;ab=0;
                res[i].a1+=a;br-=a;a=0;
                res[i].b1+=br;br-=b;b-=br;
                res[i].o1+=br;o-=br;
            }
            resenje = false;
        }

    }

    if(resenje) cout << "nemoguce" <<endl;
    else {
        cout << "moguce" <<endl;
        for( int i=1;i<=n;i++ ){
            cout << res[i].o1<< " " << res[i].a1<< " " <<res[i].b1 << " " << res[i].ab1 <<endl;
        }
    }

return 0;
}