#include <bits/stdc++.h>
using namespace std;
long long n,o,a,b,ab,c[100005],rez[100005][5],br,temp;
bool pojavo;
string  grupa[100005];
int main(){
cin>>n;
cin>>o>>a>>b>>ab;
for(int i=1;i<=n;i++){
	cin>>grupa[i]>>c[i];
}

//cout<<osto<<" "<<osta<<" "<<ostb<<" "<<ostab<<endl;
for(int i=1;i<=n;i++){
	if(grupa[i]=="O" and o-c[i]>=0){
			rez[i][1]=c[i];
	o-=c[i];
	}
	if(o<0){
		cout<<"nemoguce"<<endl;
		return 0;
	}
}
//cout<<o<<" "<<a<<" "<<b<<" "<<ab<<endl;
for(int i=1;i<=n;i++){
	if(grupa[i]=="A" and a-c[i]>=0){
			rez[i][2]=c[i];
	a-=c[i];
	}
	else if(grupa[i]=="A" and a>0 and a-c[i]<0 and o-c[i]+a>=0){
			rez[i][1]=c[i]-a;
			rez[i][2]=a;
			o-=c[i]-a;
			a=0;
	}
	else if(grupa[i]=="A" and a<=0 and o-c[i]>=0){
		rez[i][1]=c[i];
		o-=c[i];
	}
	else if(grupa[i]=="A" and a<=0 and (o-c[i]<0 or o<=0)){
		cout<<"nemoguce"<<endl;
		return 0;
	}
}
//cout<<o<<" "<<a<<" "<<b<<" "<<ab<<endl;
for(int i=1;i<=n;i++){
	if(grupa[i]=="B" and b-c[i]>=0){
			rez[i][3]=c[i];
	b-=c[i];
	}
	else if(grupa[i]=="B" and b>0 and b-c[i]<0 and o-c[i]+b>=0){
			rez[i][1]=c[i]-b;
			rez[i][3]=b;
			o-=c[i]-b;
			b=0;
	}
	else if(grupa[i]=="B" and b<=0 and o-c[i]>=0){
		rez[i][1]=c[i];
		o-=c[i];
	}
	else if(grupa[i]=="B" and b<0 and (o-c[i]<0 or o<=0)){
		cout<<"nemoguce"<<endl;
		return 0;
	}
}

//cout<<o<<" "<<a<<" "<<b<<" "<<ab<<endl;

for(int i=1;i<=n;i++){

	if(grupa[i]=="AB"){
            br=6;
            temp=c[i];
        while(c[i]>0){
                //cout<<c[i]<<" "<<ab<<" "<<br<<endl;
            if(br==6 and ab>0 and c[i]>=ab){

            rez[i][4]=ab;
            c[i]-=ab;
            ab-=temp;
            }
            else if(br==6 and ab>0 and c[i]<ab){
                rez[i][4]=c[i];
                c[i]-=ab;
                ab-=temp;
            }
            if(br==5 and o>0 and c[i]>=o){
                rez[i][1]=o;
                c[i]-=o;
                o-=temp;

            }
            else if(br==5 and o>0 and c[i]<o){
                rez[i][1]=c[i];
                c[i]-=o;
                o-=temp;
            }
            if(br==4 and a>0 and c[i]>=a){
                rez[i][2]=a;
                c[i]-=a;
                a-=temp;
            }
            else if(br==4 and a>0 and c[i]<a){
                rez[i][2]=c[i];
                c[i]-=a;
                a-=temp;
            }
            if(br==3 and b>0 and c[i]>=b){
                rez[i][3]=b;
                c[i]-=b;
                b-=temp;
            }
            else if(br==3 and b>0 and c[i]<b){
                rez[i][3]=c[i];
                c[i]-=b;
                b-=temp;
            }
            br--;
            if(rez[i][1]+rez[i][2]+rez[i][3]+rez[i][4]==c[i]){
                cout<<"nemoguce"<<endl;
                return 0;
            }
        }
	}

}

cout<<"moguce"<<endl;
for(int i=1;i<=n;i++){
	for(int j=1;j<=4;j++){
		cout<<rez[i][j]<<" ";
	}
	cout<<endl;
}

return 0;
}