#include <bits/stdc++.h>

using namespace std;

typedef struct K
{
	int o = 0, a = 0, b = 0, ab = 0, g, uk;
} krv;

krv k[10010];

string s;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n, O, A, B, AB;
	
	cin >> n;
	cin >> O >> A >> B >> AB;
	
	for(int i = 0; i < n; i++)
	{
		cin >> s;
		
		if(s.size() > 1) k[i].g = 3;
		else if(s[0] == 'O') k[i].g = 0;
		else if(s[0] == 'A') k[i].g = 1;
		else if(s[0] == 'B') k[i].g = 2;
		
		cin >> k[i].uk;
	}
	
	for(int i = 0; i < n; i++)
	{
		if(k[i].g == 0)
		{
			int c = min(k[i].uk, O);
			
			k[i].uk -= c;
			k[i].o += c;
			O -= c;
		}
	}
	
	for(int i = 0; i < n; i++)
	{
		if(k[i].g == 1)
		{
			if(A)
			{
				int c = min(k[i].uk, A);
			
				k[i].uk -= c;
				k[i].a += c;
				A -= c;
			}
			
			if(k[i].uk)
			{
				int c = min(k[i].uk, O);
			
				k[i].uk -= c;
				k[i].o += c;
				O -= c;
			}
		}
	}
	
	for(int i = 0; i < n; i++)
	{
		if(k[i].g == 2)
		{
			if(B)
			{
				int c = min(k[i].uk, B);
			
				k[i].uk -= c;
				k[i].b += c;
				B -= c;
			}
			
			if(k[i].uk)
			{
				int c = min(k[i].uk, O);
			
				k[i].uk -= c;
				k[i].o += c;
				O -= c;
			}
		}
	}
	
	for(int i = 0; i < n; i++)
	{
		if(k[i].g == 3)
		{
			if(AB)
			{
				int c = min(k[i].uk, AB);
			
				k[i].uk -= c;
				k[i].ab += c;
				AB -= c;
			}
			
			if(k[i].uk)
			{
				int c = min(k[i].uk, O);
			
				k[i].uk -= c;
				k[i].o += c;
				O -= c;
			}
			
			if(k[i].uk)
			{
				int c = min(k[i].uk, A);
			
				k[i].uk -= c;
				k[i].a += c;
				A -= c;
			}
			
			if(k[i].uk)
			{
				int c = min(k[i].uk, B);
			
				k[i].uk -= c;
				k[i].b += c;
				B -= c;
			}
			
			
		}
	}
	
	for(int i = 0; i < n; i++)
	{
		if(k[i].uk)
		{
			cout << "nemoguce";
			return 0;
		}
	}
	
	cout << "moguce\n";
	
	for(int i = 0; i < n; i++)
		cout << k[i].o << " " << k[i].a << " " << k[i].b << " " << k[i].ab << "\n";
	
	return 0;
}