#include <bits/stdc++.h>
#define MAXN 10010
#define fi first
#define se second
using namespace std;

int r[MAXN][4];

pair<string, int> q[MAXN];

int main()
{
    int n;
    cin >> n;
    int o, a, b, ab;
    cin >> o >> a >> b >> ab;
    for(int i = 0; i < n; i++)
    {
        cin >> q[i].fi >> q[i].se;
    }
    bool ind = true;
    for(int i = 0; i < n; i++)
    {
        if(q[i].fi == "O")
        {
            o -= q[i].se;
            r[i][0] += q[i].se;
        }
        if(o < 0)
        {
            ind = false;
            break;
        }
    }
    for(int i = 0; i < n && ind; i++)
    {
        if(q[i].fi == "A")
        {
            int k = min(a, q[i].se);
            a -= k;
            r[i][1] = k;
            k = q[i].se - k;
            o -= k;
            r[i][0] = k;
        }
        if(o < 0)
        {
            ind = false;
            break;
        }
    }
    for(int i = 0; i < n && ind; i++)
    {
        if(q[i].fi == "B")
        {
            int k = min(b, q[i].se);
            b -= k;
            r[i][2] = k;
            k = q[i].se - k;
            o -= k;
            r[i][0] = k;
        }
        if(o < 0)
        {
            ind = false;
            break;
        }
    }
    for(int i = 0; i < n && ind; i++)
    {
        if(q[i].fi == "AB")
        {
            int k = min(ab, q[i].se);
            //cout << "| " << q[i].se << ": " << k << " ";
            ab -= k;
            r[i][3] = k;
            int ka = min(a, q[i].se - k);
            //cout << ka << " ";
            a -= ka;
            r[i][1] = ka;
            int kb = min(b, q[i].se - (k + ka));
            //cout << kb << " ";
            b -= kb;
            r[i][2] = kb;
            int ko = q[i].se - (k + ka + kb);
            //cout << ko << endl;
            o -= ko;
            r[i][0] = ko;
        }
        if(o < 0)
        {
            ind = false;
            break;
        }
    }
    if(!ind)
    {
        cout << "nemoguce" << endl;
    }
    else
    {
        for(int i = 0; i < n; i++)
        {
            cout << r[i][0] << " " << r[i][1] << " " << r[i][2] << " " << r[i][3] << endl;
        }
    }

    return 0;
}






/*
ab -= min(ab, q[i].se);
r[i][3] = min(ab, q[i].se);
a -= min(a, q[i].se - min(ab, q[i].se));
r[i][1] = min(a, q[i].se - min(ab, q[i].se));
b -= min(b, q[i].se - min(a, q[i].se - min(ab, q[i].se)));
r[i][2] = min(b, q[i].se - min(a, q[i].se - min(ab, q[i].se)));
o -= q[i].se - min(b, q[i].se - min(a, q[i].se - min(ab, q[i].se)));
r[i][0] = q[i].se - min(b, q[i].se - min(a, q[i].se - min(ab, q[i].se)));
*/