#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector < pair <int, int> > a[4];
    int n, krv[4];
    scanf("%u", &n);
    int mat[n][4];
    scanf("%u %u %u %u", &krv[0], &krv[1], &krv[2], &krv[3]);
    for (int i = 0; i < n; i++) {
        string c;
        int b;
        cin >> c >> b;
        if (c == "O") {
            a[0].push_back({b,i});
        }
        else if (c == "A") {
            a[1].push_back({b,i});
        }
        else if (c == "B") {
            a[2].push_back({b,i});
        }
        else {
            a[3].push_back({b,i});
        }
    }
    for (int i = 0; i < 4; i++) {
        for (vector<pair<int, int> >::iterator it = a[i].begin(); it != a[i].end(); it++) {
            for (int j = 0; j < 4; j++) {
                mat[(*it).second][j] = 0;
                if (j <= i) {
                    if (i == 2 && j == 1) {
                        j++;
                        mat[(*it).second][j] = 0;
                    }
                    if ((*it).first != 0) {
                        if ((*it).first > krv[j]) {
                            if (i == j) {
                                printf("nemoguce");
                                exit(0);
                            }
                            else {
                                (*it).first -= krv[j];
                                mat[(*it).second][j] = krv[j];
                                krv[j] = 0;
                            }
                        }
                        else {
                            mat[(*it).second][j] = (*it).first;
                            krv[j] -= (*it).first;
                            (*it).first = 0;
                        }
                    }
                }
            }
        }
    }
    printf("moguce\n");
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            printf("%d ", mat[i][j]);
        }
        printf("\n");
    }
}