#include <bits/stdc++.h>

using namespace std;

int
main ()
{

  int n, o, a, b, ab;
  cin >> n;
  bool m = false;
  pair < string, int >gas[n + 2];
  cin >> o >> a >> b >> ab;
  int O[n + 2], A[n + 2], B[n + 2], AB[n + 2], AB2[n + 2];
  int AB3=0;
  for (int i = 0; i < n; i++)
    {
      O[i] = 0;
      A[i] = 0;
      B[i] = 0;
      AB[i] = 0;
      AB2[i] = 0;
      cin >> gas[i].first >> gas[i].second;
      if (gas[i].first == "O")
	    {
	    if (gas[i].second > o)
	    m = true;
	    else
	        {
	        O[i] += gas[i].second;
	        o -= gas[i].second;
	        }

	    }
        else if (gas[i].first == "A")
	        {
	        if (gas[i].second < a)
	            {
	            A[i] += gas[i].second;
	            a -= gas[i].second;
	            }
	        else
	            {
	            A[i] += a;
	            a = 0;
                gas[i].second-=A[i];
	            if (gas[i].second > o)
	                {
	                m = true;
	                }
	            else
	                {
	                O[i] += gas[i].second;
	                o -= gas[i].second;
	                }
	            }

	}
	else if (gas[i].first == "B")
	    {
	    if (gas[i].second < b)
	        {
	        B[i] += gas[i].second;
	        b -= gas[i].second;

	        }
	    else
	        {
	        B[i] += b;
	         a = 0;
            gas[i].second-=B[i];
	        if (gas[i].second > o)
	        m = true;
	        else
	            {
	            O[i] += gas[i].second;
	            o -= gas[i].second;
	            }
	        }

	    }
	else if (gas[i].first == "AB")
	    {
	        if (gas[i].second < ab)
	        {
	        AB[i] += gas[i].second;
	        ab -= gas[i].second;
        gas[i].second=0;
	        }
	        else
	            {
	            AB[i] += ab;
	            ab = 0;
                gas[i].second-=AB[i];
	            AB2[i]+=gas[i].second;
	            AB3+=gas[i].second;
	            }
	    }
    }
    if(m || AB3>o+a+b+ab)
        {
        cout<<"nemoguce";
        }
    else
        {
        cout<<"moguce"<<endl;    
        for(int i=0;i<n;i++)
            {
            if(gas[i].first!="AB" || gas[i].second==0)
                {
                 
                }
            else
                {
                if (gas[i].second < o)
	                {
	                O[i] += gas[i].second;
	                o -= gas[i].second;
	                }
	            else
	                {
	                gas[i].second-=o;
	                O[i]+=o;
	                o=0;
	                if (gas[i].second < a)
	                    {
	                    A[i] += gas[i].second;
	                    a -= gas[i].second;
	                    }
	                else
	                    {
	                    gas[i].second-=a;
	                    A[i]+=a;
	                    a=0;
	                    B[i] += gas[i].second;
	                    b -= gas[i].second;
	                    }
	                    
	                }
                }
                   cout<<O[i]<<" "<<A[i]<<" "<<B[i]<<" "<<AB[i]<<endl;
                
            }
        }
        

}