#include <bits/stdc++.h>
using namespace std;

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define mp make_pair
#define parll pair<ll,ll>
#define parii pair<int,int>
#define nzd __gcd
#define nzs(e1,e2) (e1/nzd(e1,e2))*e2
#define min3(brp1,brp2,brp3) min(brp1,min(brp2,brp3))
#define min4(brp1,brp2,brp3,brp4) min(brp1,min3(brp2,brp3,brp4))
#define max3(brp1,brp2,brp3) max(brp1,max(brp2,brp3))
#define max4(brp1,brp2,brp3,brp4) max(brp1,max3(brp2,brp3,brp4))
#define l_b(BRL,brl) lower_bound( BRL.begin(), BRL.end(), brl )-BRL.begin()-1 /// !za one based! vraca mani iako brl postoji, vraca 0 kada ne postoji manji
#define u_b(BRU,bru) upper_bound( BRU.begin(), BRU.end(), bru )-BRU.begin() /// !za one based! vraca veci iako bru postoji, vraca n+1 kada ne postoji veci
#define mod 1000000007
#define mxn 10002

ll n,o,a,b,ab,zo,za,zb,zab;
vector < pair<string,ll> > A;

int main()
{
    ios;

    cin >> n;
    cin >> zo >> za >> zb >> zab;
    string s; ll p;
    vector <ll> V0(4,0);
    vector < vector<ll> > R(n+1,V0);
    for ( ll i = 1; i <= n; i++ )
    {
        cin >> s >> p;
        A.push_back({s,p});
    }

    for ( ll i = 0; i < n; i++ )
    {
        if ( A[i].first == "O" )
        {
            if ( A[i].second > zo )
            {
                cout << "nemoguce";
                return 0;
            }
            zo -= A[i].second;
            R[i][0] = A[i].second;
        }
    }

    ll k;
    for ( ll i = 0; i < n; i++ )
    {
        if ( A[i].first == "A" )
        {
            if ( A[i].second > zo+za )
            {
                cout << "nemoguce";
                return 0;
            }
            k = za;
            za = max( za-A[i].second, 0ll );
            A[i].second = max( A[i].second-k, 0ll );
            R[i][1] = k-za;
            k = zo;
            zo = max( zo-A[i].second, 0ll );
            R[i][0] = k-zo;
        }
    }

    for ( ll i = 0; i < n; i++ )
    {
        if ( A[i].first == "B" )
        {
            if ( A[i].second > zo+zb )
            {
                cout << "nemoguce";
                return 0;
            }
            k = zb;
            zb = max( zb-A[i].second, 0ll );
            A[i].second = max( A[i].second-k, 0ll );
            R[i][2] = k-zb;
            k = zo;
            zo = max( zo-A[i].second, 0ll );
            R[i][0] = k-zo;
        }
    }

    for ( ll i = 0; i < n; i++ )
    {
        if ( A[i].first == "AB" )
        {
            if ( A[i].second > zo+za+zb+zab )
            {
                cout << "nemoguce";
                return 0;
            }
            k = zab;
            zab = max( zab-A[i].second, 0ll );
            A[i].second = max( A[i].second-k, 0ll );
            R[i][3] = k-zab;
            k = zb;
            zb = max( zb-A[i].second, 0ll );
            A[i].second = max( A[i].second-k, 0ll );
            R[i][2] = k-zb;
            k = za;
            za = max( za-A[i].second, 0ll );
            A[i].second = max( A[i].second-k, 0ll );
            R[i][1] = k-za;
            k = zo;
            zo = max( zo-A[i].second, 0ll );
            A[i].second = max( A[i].second-k, 0ll );
            R[i][0] = k-zo;
        }
    }

    for ( ll i = 0; i < n; i++ )
    {
        for ( ll j = 0; j < 4; j++ )
        {
            cout << R[i][j] << " ";
        }
        cout << "\n";
    }

    return 0;
}