#include <iostream>
#include <string>

using namespace std;

int main()
{
    int N, O, A, B, AB;
    
    cin>>N;
    cin>>O>>A>>B>>AB;
    
    string kg[N];
    int kol[N];
    
    for(int i = 0; i < N; i++)
    {
        cin>>kg[i];
        cin>>kol[i];
    }

    int memo[N][4];
    
    for(int i = 0; i < N; i++)
    {
        memo[i][0] = 0;
        memo[i][1] = 0;
        memo[i][2] = 0;
        memo[i][3] = 0;
    }
    
    for(int i = 0; i < N; i++)
    {
        if(kg[i] == "O")
        {
            O -= kol[i];
            memo[i][0] += kol[i];
        }
    }
    
    if(O < 0)
    {    
        cout<<"nemoguce";
        return 0;
    }
    
    for(int i = 0; i < N; i++)
    {
        if(kg[i] == "A")
        {
            if(A >= kol[i])
            {
                A -= kol[i];
                memo[i][1] += kol[i];
            }
            else if(A < kol[i])
            {
                O -= kol[i] - A;
                memo[i][1] += A;
                memo[i][0] += kol[i] - A;
                A = 0;
            }
        }
        
    }
    
    if(O < 0)
    {    
        cout<<"nemoguce";
        return 0;
    }
    
    for(int i = 0; i < N; i++)
    {
        if(kg[i] == "B")
        {
            if(B >= kol[i])
            {
                B -= kol[i];
                memo[i][2] += kol[i];
            }
            else if(B < kol[i])
            {
                O -= kol[i] - B;
                memo[i][2] += B;
                memo[i][0] += kol[i] - B;
                B = 0;
            }
        }
        
    }
    
    if(O < 0)
    {    
        cout<<"nemoguce";
        return 0;
    }
    
    for(int i = 0; i < N; i++)
    {
        if(kg[i] == "AB")
        {
            if(AB >= kol[i])
            {
                AB -= kol[i];
                memo[i][3] += kol[i];
            }
            else if(AB < kol[i])
            {
                memo[i][3] += AB;
                
                if(A >= kol[i] - AB)
                {
                    A -= kol[i] - AB;
                    memo[i][1] += kol[i] - AB;
                }
                else if(A < kol[i] - AB)
                {
                    memo[i][1] += A;
                
                    if(B >= kol[i] - AB - A)
                    {
                        B -= kol[i] - AB - A;
                        memo[i][2] += kol[i] - AB - A;
                    }
                    else if(B < kol[i] - AB - A)
                    {
                        memo[i][0] += kol[i] - AB - A -B;
                        O -= kol[i] - AB - A -B;
                    }
                        
                    A = 0;
                }
                
                AB = 0;
            }
        }
    }
    
    if(O < 0)
    {    
        cout<<"nemoguce";
        return 0;
    }
    
    cout<<"moguce"<<"\n";
    for(int i = 0; i < N; i++)
        cout<<memo[i][0]<<" "<<memo[i][1]<<" "<<memo[i][2]<<" "<<memo[i][3]<<"\n";
    
    return 0;
}