#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, o, a, b, ab, br;
    string grupa;
    cin >> n >> o >> a >> b >> ab;
    int niz[1000][4];
    int nizAB[1000]; int k = 0;
    int nizABBR[1000]; int brk = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> grupa >> br;
        if(grupa == "O") {niz[i][0]=br; niz[i][1]=niz[i][2]=niz[i][3]=0; o-=br;}
        else if(grupa == "A") {if(a < br) {niz[i][1] = a; niz[i][0] = br - a; o -= br - a; a = 0; niz[i][2]=niz[i][3]=0;} niz[i][1]=br; niz[i][0]=niz[i][2]=niz[i][3]=0; a-=br;}
        else if(grupa == "B") {if(b < br) {niz[i][2] = b; niz[i][0] = br - b; o -= br - b; b = 0; niz[i][1]=niz[i][3]=0;} niz[i][2]=br; niz[i][0]=niz[i][1]=niz[i][3]=0; b-=br;}
        else if(grupa == "AB") {nizAB[k] = i; nizABBR[k++] = br;}
        if(o < 0)
        {
            cout << "nemoguce";
            return 0;
        }
    }
    for(int i = 0; i < k; i++)
    {
        int br = nizABBR[i];
        int j = nizAB[i];
        if(ab >= br)
        {
            ab -= br;
            niz[j][3]=br;
            niz[j][0]=niz[j][1]=niz[j][2]=0;
            continue;
        }
        niz[j][3] = ab;
        br -= ab;
        if(b >= br)
        {
            b -= br;
            niz[j][2]=br;
            niz[j][0]=niz[j][1]=0;
            continue;
        }
        niz[j][2] = b;
        br -= b;
        if(a >= br)
        {
            a -= br;
            niz[j][1]=br;
            niz[j][0]=0;
            continue;
        }
        niz[j][1] = a;
        br -= a;
        if(o >= br)
        {
            o -= br;
            niz[j][0]=br;
            continue;
        }
        cout<<"nemoguce"; return 0;
    }
    cout<<"moguce \n";
    for(int i = 0; i < n; i++) cout<<niz[i][0]<<" "<<niz[i][1]<<" "<<niz[i][2]<<" "<<niz[i][3]<<"\n";
    return 0;
}