// I may fail a thousand times
// But there is no giving up
// IOI - here I come
#include <bits/stdc++.h>
#define int long long
using namespace std;
int rem[4];
vector<pair<int,int>> v[4];
int ans[(int)1e4+5][4];
vector<int> adj[4];
signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n>>rem[0]>>rem[1]>>rem[2]>>rem[3];
	adj[0].push_back(0);
	adj[1].push_back(1);
	adj[1].push_back(0);
	adj[2].push_back(2);
	adj[2].push_back(0);
	adj[3].push_back(3);
	adj[3].push_back(2);
	adj[3].push_back(1);
	adj[3].push_back(0);
	for(int i=0;i<n;i++){
		string x;cin>>x;
		int y;cin>>y;
		int p=0;
		if(x=="A")p=1;
		else if(x=="B")p=2;
		else if(x=="AB")p=3;
		v[p].push_back(make_pair(i,y));
	}
	for(int i=0;i<4;i++){
		for(auto j:v[i]){
			int sum=0;int flag=0;
			for(int k=0;k<(int)adj[i].size();k++){
				int tmp=min(j.second-sum,rem[adj[i][k]]);
				ans[j.first][adj[i][k]]+=tmp;
				rem[adj[i][k]]-=tmp;
				sum+=tmp;
				if(sum>=j.second){
					flag=1;
					break;
				}
			}
			if(!flag){
				cout<<"nemoguce\n";
				return 0;
			}
		}
	}
	cout<<"moguce\n";
	for(int i=0;i<n;i++){
		for(int j=0;j<4;j++){
			cout<<ans[i][j]<<' ';
		}
		cout<<'\n';
	}
	return 0;
}