#include <bits/stdc++.h>

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 grog[4] {1,2,3,4};
    vector<vector<int> > niz;
    vector<int> nizAB; int k = 0;
    vector<int> nizABBR; int brk = 0;
    for(int i = 0; i < n; i++)
    {
        vector<int> g(4,0);
        niz.push_back(g);
        nizAB.push_back(0);
        nizABBR.push_back(0);
    }
    for (int i = 0; i < n; i++)
    {
        cin >> grupa >> br;
        if(grupa == "O") {niz.at(i)[0]=br; niz.at(i)[1]=niz.at(i)[2]=niz.at(i)[3]=0; o-=br;}
        else if(grupa == "A") {if(a < br) {niz.at(i)[1] = a; niz.at(i)[0] = br - a; o -= br - a; a = 0; niz.at(i)[2]=niz.at(i)[3]=0;} else {niz.at(i)[1]=br; niz.at(i)[0]=niz.at(i)[2]=niz.at(i)[3]=0; a-=br;}}
        else if(grupa == "B") {if(b < br) {niz.at(i)[2] = b; niz.at(i)[0] = br - b; o -= br - b; b = 0; niz.at(i)[1]=niz.at(i)[3]=0;} else {niz.at(i)[2]=br; niz.at(i)[0]=niz.at(i)[1]=niz.at(i)[3]=0; b-=br;}}
        else if(grupa == "AB") {nizAB.at(k) = i; nizABBR.at(k++) = br;}
        if(o < 0)
        {
            cout << "nemoguce";
            return 0;
        }
    }
    for(int i = 0; i < k; i++)
    {
        int br = nizABBR.at(i);
        int j = nizAB.at(i);
        if(ab >= br)
        {
            ab -= br;
            niz.at(j)[3]=br;
            niz.at(j)[0]=niz.at(j)[1]=niz.at(j)[2]=0;
            continue;
        }
        niz.at(j)[3] = ab;
        br -= ab;
        if(b >= br)
        {
            b -= br;
            niz.at(j)[2]=br;
            niz.at(j)[0]=niz.at(j)[1]=0;
            continue;
        }
        niz.at(j)[2] = b;
        br -= b;
        if(a >= br)
        {
            a -= br;
            niz.at(j)[1]=br;
            niz.at(j)[0]=0;
            continue;
        }
        niz.at(j)[1] = a;
        br -= a;
        if(o >= br)
        {
            o -= br;
            niz.at(j)[0]=br;
            continue;
        }
        cout<<"nemoguce"; return 0;
    }
    cout<<"moguce \n";
    for(int i = 0; i < n; i++) cout<<niz.at(i)[0]<<" "<<niz.at(i)[1]<<" "<<niz.at(i)[2]<<" "<<niz.at(i)[3]<<"\n";
    return 0;
}