#include <iostream>
#include <array>
#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;
};
int n, blood[4];
vector<array<int, 4>> krv;
void give(trp& pac, int type) {
    int g = min(pac.z, blood[type]);
    krv[pac.x][type] += g;
    blood[type] -= g;
    pac.z -= g;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> blood[0] >> blood[1] >> blood[2] >> blood[3];
    vector<trp> pac(n);
    krv.assign(n, {0, 0, 0, 0});
    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;
    }
    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 type: red[pac[i].y]) give(pac[i], type);
        if (pac[i].z > 0) q();
    }
    cout << "moguce" << endl;
    forn(i, n) {
        for (int e: krv[i]) cout << e << " ";
        cout << endl;
    }
}