#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int n;
    int o, a, b, ab;
    string krvna_grupa[n];
    int potrebna_kolicina[n];
    int zbir = 0;
    
    cin >> n;
    cin >> o >> a >> b >> ab;
    
    for(int i = 0; i < n; i++)
    {
        cin >> krvna_grupa[i] >> potrebna_kolicina[i];
        
        zbir += potrebna_kolicina[i];
        
        if((krvna_grupa[i]=="O") && (o-potrebna_kolicina[i])<0)
        {
            cout << "nemoguce";
        }
    }
    
    if((a+o)-zbir<0)
        {
            cout << "nemoguce";
            goto end;
        }
    
    cout << "moguce" << endl;
    for(int i = 0; i < n; i++)
    {
        if(krvna_grupa[i]=="A")
        {
            a -=potrebna_kolicina[i];
            
            if(a < 0)
            {
                o -=abs(a);
                cout << abs(a) << " " << potrebna_kolicina[i]-abs(a) << " " << 0 << " " << 0 << endl;
                continue;
            }
            cout << 0 << " " << potrebna_kolicina[i] << " " << 0 << " " << 0 << endl;
            continue;
        }
        
        else if(krvna_grupa[i]=="O")
        {
            o -=potrebna_kolicina[i];
            
            cout << potrebna_kolicina[i] << " " << 0 << " " << 0 << " " << 0 << endl;
            continue;
        }
    }
    
    end:
    return 0;
}