#include <bits/stdc++.h>
using namespace std;
//Zadatak: Transfuzija krvi

int main()
{
	int n;
	cin>>n;
	int o,a,b,ab;
	cin >> o >> a >> b >>ab;
	vector<pair<string, int>> p(n); //pacijenti
	int ukupno_treba=0;

	for (int i = 0; i < n; i++)
	{
			cin >> p[i].first >> p[i].second;   //first - krvna grupa, second - broj zaliha
			ukupno_treba+=p[i].second; 
	}

	int treba_A=0, treba_0=0, treba_B=0, treba_AB=0;
	for(int i = 0; i < p.size(); i++)
	{
		if (p[i].first == "O") treba_0+=p[i].second;	
		else if (p[i].first == "A") treba_A+=p[i].second;		
		else if (p[i].first == "B") treba_B+=p[i].second;		
		else if (p[i].first == "AB") treba_AB+=p[i].second;
	}

	//bazni slucajevi
	if (o+a+b+ab < ukupno_treba) cout<< "nemoguce";
	else if (treba_0>o || treba_A>a+o-treba_0 || treba_B>b+o-treba_0 || treba_AB>ab+a+b+o-treba_0) cout << "nemoguce";

	else 
	{
		cout << "moguce" <<endl;  
		int matrica[n][4];

		for (int i = 0; i < n; ++i)
		{ 
				if(p[i].first == "A") {
					matrica[i][2]=0;
					matrica[i][3]=0;
					if(a>0) {
						if(a>p[i].second) 
							{ 
								matrica[i][1]=p[i].second;
								matrica[i][0]=0;
							}
						else
							{
								matrica[i][1]=a;
								matrica[i][0]=p[i].second-a;
								o=o-(p[i].second-a);
							}
					}
					else if (a==0)
					{
						matrica[i][1]=0;
						matrica[i][0]=p[i].second;
						o-=p[i].second;
					}
				}


				else if(p[i].first == "B") {
					matrica[i][1]=0;
					matrica[i][3]=0;
					if(b>0) {
						if(b>p[i].second) 
							{ 
								matrica[i][2]=p[i].second;
								matrica[i][0]=0;
							}
						else
							{
								matrica[i][2]=b;
								matrica[i][0]=p[i].second-b;
								o=o-(p[i].second-b);
							}
					}
					else if (b==0)
					{
						matrica[i][2]=0;
						matrica[i][0]=p[i].second;
						o-=p[i].second;
					}
					
				}
				else if(p[i].first == "AB") {
					
					if(ab>0)
					{
						if(ab>p[i].second)
						{
							matrica[i][3]=p[i].second;
							ab-=p[i].second;
							matrica[i][0]=0;
							matrica[i][2]=0;
							matrica[i][3]=0;
						}
						else
						{
							matrica[i][3]=ab;
							p[i].second-=ab;
						}
					}
				}
				else if(p[i].first == "O") {
					matrica[i][1]=0;
					matrica[i][2]=0;
					matrica[i][3]=0;
					matrica[i][0]=p[i].second;
					o-=p[i].second;
					//treba_0-=a[i].second;
				}
		}

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				cout << matrica[i][j] << ' ';
			}
			cout<<endl;
		}

	}
}