#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	
	int n;
	cin >>n;
	int bbags[4];
	for(int i=0;i<4;i++)
	{
		cin >>bbags[i];
	}
	int m[n][4];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<4;j++)
		{
			m[i][j]=0;
		}
	}
	vector<pair<int,int> > v;
	for(int z=0;z<n;z++)
	{
		string s;
		cin >>s;
		int x;
		cin >>x;
		if(s=="O")
		{
			int pom=min(x,bbags[0]);
			x=x-pom;
			bbags[0]=bbags[0]-pom;
			m[z][0]+=pom;
			if(x>0)
			{
				
				for(int q=z+1;q<n;q++)
				{
					string s2;
					cin >>s2;
					int x2;
					cin >>x2;
				}
				cout <<"nemoguce\n";
				return 0;
			}
			
		}
		else if(s=="A")
		{
			int pom=min(x,bbags[1]);
			x=x-pom;
			bbags[1]=bbags[1]-pom;
			m[z][1]+=pom;
			pom=min(x,bbags[0]);
			x=x-pom;
			bbags[0]=bbags[0]-pom;
			m[z][0]+=pom;
			if(x>0)
			{
				
				for(int q=z+1;q<n;q++)
				{
					string s2;
					cin >>s2;
					int x2;
					cin >>x2;
				}
				cout <<"nemoguce\n";
				return 0;
			}
		}
		else if(s=="B")
		{
			int pom=min(x,bbags[2]);
			x=x-pom;
			bbags[2]=bbags[2]-pom;
			m[z][2]+=pom;
			pom=min(x,bbags[0]);
			x=x-pom;
			bbags[0]=bbags[0]-pom;
			m[z][0]+=pom;
			if(x>0)
			{
				
				for(int q=z+1;q<n;q++)
				{
					string s2;
					cin >>s2;
					int x2;
					cin >>x2;
				}
				cout <<"nemoguce\n";
				return 0;
			}
		}
		else
		{
			v.push_back(make_pair(x,z));
		}
		
	}
	
	for(int z=0;z<v.size();z++)
	{
		int pom=min(v[z].first,bbags[3]);
		v[z].first=v[z].first-pom;
		bbags[3]=bbags[3]-pom;
		m[v[z].second][3]+=pom;
		pom=min(v[z].first,bbags[2]);
		v[z].first=v[z].first-pom;
		bbags[2]=bbags[2]-pom;
		m[v[z].second][2]+=pom;
		pom=min(v[z].first,bbags[1]);
		v[z].first=v[z].first-pom;
		bbags[1]=bbags[1]-pom;
		m[v[z].second][1]+=pom;
		pom=min(v[z].first,bbags[0]);
		v[z].first=v[z].first-pom;
		bbags[0]=bbags[0]-pom;
		m[v[z].second][0]+=pom;
		if(v[z].first>0)
		{
			cout <<"nemoguce\n";
			return 0;
		}
		
	}
	
	cout <<"moguce\n";
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<4;j++)
		{
			cout <<m[i][j]<<" ";
		}
		cout <<"\n";
	}
	
	return 0;
}