#include <bits/stdc++.h>

using namespace std;

int main() {

    int n;
    scanf("%d",&n);
    int o,a,b,ab;
    scanf("%d%d%d%d",&o,&a,&b,&ab);
    vector<pair<int, int>> v;
    int** sol = (int**)malloc(n*sizeof(int*));
    for (int i = 0; i < n; ++i) {

        sol[i] = (int*)calloc(4,sizeof(int));

    }
    for (int i = 0; i < n; ++i) {
        string c; int j;
        int vr;
        cin >> c >> j;
        if (c=="O") {sol[i][0] = o-j; o-=j; if (o<0) {printf("nemoguce\n"); return 0;}}
        if (c=="A") {if (a-j<0) {sol[i][1]=a; j-=a; sol[i][0] = o-j; o-=j; if (o<0){printf("nemoguce\n"); return 0;}} else {sol[i][1]=j; a-=j;}}
        if (c=="B") {if (b-j<0) {sol[i][2]=b; j-=b; sol[i][0] = o-j; o-=j; if (o<0){printf("nemoguce\n"); return 0;}} else {sol[i][2]=j; b-=j;}}
        if (c=="AB") v.push_back({i,j});
        //printf("%d\n", vr);
        //v[i] = {vr, j};
    }

    for (auto p : v) {

        int i = p.first;
        int j = p.second;
        if (ab-j<0) {

            sol[i][3]=ab;
            j-=ab;

            if (o<j) {sol[i][0]=o;j-=o;o=0;}
            else if (o>=j) {sol[i][0]=j; o-=j; j=0; continue;}

            if (a<j) {sol[i][1]=a; j-=a; a=0;}
            else if (a>=j) {sol[i][1]=j; a-=j; j=0; continue;}

            if (b<j) {sol[i][2]=b; j-=b; b=0;}
            else if (b>=j) {sol[i][2]=j; b-=j; j=0; continue;}

            if (j>0) {printf("nemoguce\n"); return 0;}

        }

        else {

            sol[i][3] = j;
            ab-=j;
            continue;

        }


    }

    printf("moguce\n");
for (int i = 0; i < n; ++i) {

    printf("%d %d %d %d\n", sol[i][0],sol[i][1],sol[i][2],sol[i][3]);

}

}