#include <iostream>
#include <algorithm>
#include <vector>
#define q() {cout << "nemoguce" << endl; return 0;}
#define forn(i, n) for (int i = 0; i < n; i++)
using namespace std;
struct trp {
    int x, y, z;
};
struct qdr {
    int bl[4];
};
int n, o, a, b, ab;
vector<qdr> krv;
void give(trp& pac, int type) {
    int* bt;
    if (type == 0) bt = &o;
    else if (type == 1) bt = &a;
    else if (type == 2) bt = &b;
    else bt = &ab;
    int g = min(pac.z, *bt);
    krv[pac.x].bl[type] += g;
    *bt -= g;
    pac.z -= g;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> o >> a >> b >> ab;
    vector<trp> pac(n);
    krv.assign(n, {});
    forn(i, n) {
        string s;
        cin >> s >> pac[i].z;
        pac[i].x = i;
        if (s == "O") pac[i].y = 0;
        else if (s == "A") pac[i].y = 1;
        else if (s == "B") pac[i].y = 2;
        else pac[i].y = 3;
        forn(j, 4) krv[i].bl[j] = 0;
    }
    sort(pac.begin(), pac.end(), [](trp a, trp b) {return a.y < b.y;});
    vector<int> red[4] = { {0}, {1, 0}, {2, 0}, {3, 2, 1, 0}};
    forn(i, n) {
        for (int blood: red[pac[i].y]) give(pac[i], blood);
        if (pac[i].z > 0) q();
    }
    cout << "moguce" << endl;
    forn(i, n) {
        for (int e: krv[i].bl) cout << e << " ";
        cout << endl;
    }
}