#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define ff(i,s,f) for(int i=s;i<f;i++)
#define fb(i,s,f) for(int i=(s)-1;i>=f;i--)
#define ffi(i,s,f) for(int i=s;i<=f;i++)
#define fbi(i,s,f) for(int i=s;i>=f;i--)
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,int) sort(a.begin(),a.end(),greater<int>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define ub(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define vstart auto startt=chrono::system_clock::now()
#define vend auto endd=chrono::system_clock::now()
#define vvreme chrono::duration<double> vremee=endd-startt
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef string str;

const int maxn=1e4+10;

struct covek{
    string g;
    int t;
    int po=0,pa=0,pb=0,pab=0;
};

covek niz[maxn];

void uradi(int &a,int &b){
    int pom=min(a,b);
    a-=pom;
    b-=pom;
}

void solve(){
	int n;
	cin>>n;
	int o,a,b,ab;
	cin>>o>>a>>b>>ab;
	ff(i,0,n){
        cin>>niz[i].g>>niz[i].t;
	}
	bool moguce=true;
	auto jedna=[&](string grupa){
        ff(i,0,n){
            if(niz[i].g!=grupa) continue;
            if(niz[i].g=="O"){
                int bio=niz[i].t;
                uradi(niz[i].t,o);
                niz[i].po+=bio-niz[i].t;
            }else if(niz[i].g=="A"){
                int bio=niz[i].t;
                uradi(niz[i].t,a);
                niz[i].pa+=bio-niz[i].t;
                bio=niz[i].t;
                uradi(niz[i].t,o);
                niz[i].po+=bio-niz[i].t;
            }else if(niz[i].g=="B"){
                int bio=niz[i].t;
                uradi(niz[i].t,b);
                niz[i].pb+=bio-niz[i].t;
                bio=niz[i].t;
                uradi(niz[i].t,o);
                niz[i].po+=bio-niz[i].t;
            }else{
                int bio=niz[i].t;
                uradi(niz[i].t,o);
                niz[i].po+=bio-niz[i].t;
                bio=niz[i].t;
                uradi(niz[i].t,a);
                niz[i].pa+=bio-niz[i].t;
                bio=niz[i].t;
                uradi(niz[i].t,b);
                niz[i].pb+=bio-niz[i].t;
                uradi(niz[i].t,ab);
                niz[i].pab+=bio-niz[i].t;
            }
            if(niz[i].t!=0) moguce=false;
        }
	};
	jedna("O");
	jedna("A");
	jedna("B");
	jedna("AB");
	if(!moguce){
        cout<<"nemoguce";
        return;
	}
	cout<<"moguce\n";
	ff(i,0,n){
        cout<<niz[i].po<<" "<<niz[i].pa<<" "<<niz[i].pb<<" "<<niz[i].pab<<"\n";
	}
}

int main(){
    ios;
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}