#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    int A, B, AB, O;
    cin >> O >> A >> B >> AB;
    queue<pair<int, int> > mestaO;
    queue<pair<int, int> > mestaA;
    queue<pair<int, int> > mestaB;
    queue<pair<int, int> > mestaAB;

    int ispis[n][4] = {0};

    for (int i = 0 ; i < n ; i++)
    {
        string x;
        cin >> x;
        int y;
        cin >> y;

        if (x == "O")
            mestaO.push({i, y});

        else if (x == "A")
            mestaA.push({i, y});

        else if (x == "B")
            mestaB.push({i, y});

        else
            mestaAB.push({i,y});
    }

    //resava sve O grupe
    while(!mestaO.empty())
    {
        int i = mestaO.front().first;
        int br = mestaO.front().second;
        mestaO.pop();
        if (O < br)
        {
            cout << "nemoguce" << endl;
            return 0;
        }
        else
        {
            ispis[i][0] = br;
            O -= br;
        }
        //cout << O << " " << A << " " << B << " " << AB << endl;
    }
    //resava sve A grupe
    while(!mestaA.empty())
    {
        int i = mestaA.front().first;
        int br = mestaA.front().second;
        mestaA.pop();
        //smanjuje za a;
        if (br > A)
        {
            br -= A;
            ispis[i][1] = A;
            A = 0;
        }
        else
        {
            ispis[i][1] = br;
            A -= br;
            br = 0;
        }

        //smanjuje za o
        if (O < br)
        {
            cout << "nemoguce" << endl;
            return 0;
        }
        else
        {
            ispis[i][0] = br;
            O -= br;
        }
        //cout << O << " " << A << " " << B << " " << AB << endl;

    }

    while(!mestaB.empty())
    {
        int i = mestaB.front().first;
        int br = mestaB.front().second;
        mestaB.pop();
        //smanjuje za b;
        if (br > B)
        {
            br -= B;
            ispis[i][2] = B;
            B = 0;
        }
        else
        {
            ispis[i][2] = br;
            B -= br;
            br = 0;
        }

        //smanjuje za o
        if (O < br)
        {
            cout << "nemoguce" << endl;
            return 0;
        }
        else
        {
            ispis[i][0] = br;
            O -= br;
        }
        //cout << O << " " << A << " " << B << " " << AB << endl;

    }

    //resava AB grupe
    while(!mestaAB.empty())
    {

        int i = mestaAB.front().first;
        int br = mestaAB.front().second;
        mestaAB.pop();
        //smanjuje za a;
        if (br > A)
        {
            br -= A;
            ispis[i][1] = A;
            A = 0;
        }
        else
        {
            ispis[i][1] = br;
            A -= br;
            br = 0;
        }
        //smanjuje za b
        if (br > B)
        {
            br -= B;
            ispis[i][2] = B;
            B = 0;
        }
        else
        {
            ispis[i][2] = br;
            B -= br;
            br = 0;
        }
        //smanjuje za ab;
        if (br > AB)
        {
            br -= AB;
            ispis[i][3] = AB;
            AB = 0;
        }
        else
        {
            ispis[i][3] = br;
            AB -= br;
            br = 0;
        }
        //smanjuje za o
        if (O < br)
        {
            cout << "nemoguce" << endl;
            return 0;
        }
        else
        {
            ispis[i][0] = br;
            O -= br;
        }
        //cout << O << " " << A << " " << B << " " << AB << endl;

    }
    cout << "moguce" << endl;
    for (int i = 0 ; i < n ; i++)
    {
        for (int j = 0 ; j < 4 ; j++)
            cout << ispis[i][j] << " ";
        cout << endl;
    }


}