#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin >> n;
    if (n > pow(10, 4))
        cout << "Preveliki broj";
    long long int O, A, B, AB;
    cin >> O >> A >> B >> AB;
    if (O > pow(10,6)|| A > pow(10,6)|| B > pow(10,6)|| AB > pow(10,6))
        cout << "Preveliki broj";
    vector<pair<string, long long int>> par(n);
    for(int i=0; i<n; i++)
    {
        cin >> par[i].first >> par[i].second;
        if (par[i].second > pow(10,6))
            cout << "Preveliki broj";
    }
    vector<vector<long long int>> ispis(n);
    for(int i=0; i<n; i++)
    {
        if(par[i].first == "O")
        {
            if(par[i].second <= O)
            {
                O -= par[i].second;
                ispis[i] = {par[i].second,0,0,0};
                par[i].second = 0;
            }
            else
            {
                cout << "nemoguce"; return 0;
            }
        }
        else if(par[i].first == "A")
        {
            if(par[i].second <= A)
            {
                A -= par[i].second;
                ispis[i] = {0,par[i].second,0,0};
                par[i].second = 0;
            }
            else
            {
                par[i].second -= A;
            }
            if(par[i].second > 0 && par[i].second <= O)
            {
                int pom;
                pom = par[i].second;
                O -= pom;
                ispis[i] = {par[i].second,A,0,0};
                par[i].second = 0;
                A = 0;
            }
            else if(par[i].second > 0 && par[i].second > O)
            {
                cout << "nemoguce"; return 0;
            }
        }
        else if(par[i].first == "B")
        {
            if(par[i].second <= B)
            {
                B -= par[i].second;
                ispis[i] = {0,0,par[i].second,0};
                par[i].second = 0;
            }
            else
            {
                par[i].second -= B;
            }
            if(par[i].second > 0 && par[i].second <= O)
            {
                int pom;
                pom = par[i].second;
                O -= pom;
                ispis[i] = {par[i].second,0,B,0};
                par[i].second = 0;
                B = 0;
            }
            else if(par[i].second > 0 && par[i].second > O)
            {
                cout << "nemoguce"; return 0;
            }
        }
        else if(par[i].first == "AB")
        {
            if(par[i].second <= AB)
            {
                AB -= par[i].second;
                ispis[i] = {0,0,par[i].second,0};
                par[i].second = 0;
            }
            else if(par[i].second > AB)
            {
                par[i].second -= AB;
            }
            if(par[i].second > 0 && par[i].second <= A)
            {
                int pom;
                pom = par[i].second;
                A -= pom;
                ispis[i] = {0,pom,0,AB};
                par[i].second = 0;
                AB = 0;
            }
            else if(par[i].second > 0 && par[i].second > A)
            {
                par[i].second -= A;
            }
            if(par[i].second > 0 && par[i].second <= B)
            {
                int pom;
                pom = par[i].second;
                B -= pom;
                ispis[i] = {0,A,par[i].second,AB};
                par[i].second = 0;
                AB = 0;
                A = 0;
            }
            else if(par[i].second > 0 && par[i].second > B)
            {
                par[i].second -= B;
            }
            if(par[i].second > 0 && par[i].second <= O)
            {
                int pom;
                pom = par[i].second;
                O -= pom;
                ispis[i] = {par[i].second,A,B,AB};
                par[i].second = 0;
                AB = 0;
                A = 0;
                B = 0;
            }
            else if(par[i].second > 0 && par[i].second > O)
            {
                cout << "nemoguce"; return 0;
            }
        }
        else
        {
            cout << "greska pri unosu";
            return 0;
        }
        if(i==n-1) cout << "moguce" << "\n";
        }
        for(int i=0; i<(int)ispis.size(); i++)
        {
            for(int j=0; j < 4; j++)
                cout << ispis[i][j] << " ";
        cout << "\n";
        }
    return 0;
}