#include <iostream>
#include <cstdlib>
#include <boost/lexical_cast.hpp>  

using namespace std;

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