#include <bits/stdc++.h>
using namespace std;
long long n,o,a,b,ab,c[100005],suma0,sumaa,sumab,suma,osto,osta,ostb,ostab,rez[100005][5];
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];
	if(grupa[i]=="O"){
			pojavo=true;
			suma0+=c[i];
	}
	if(grupa[i]=="A"){
			sumaa+=c[i];
	}
	if(grupa[i]=="B"){
			sumab+=c[i];
	}
	if(grupa[i]=="AB"){
			suma+=c[i];
	}

}
osto=o-suma0;
osta=a-sumaa;
ostb=b-sumab;
ostab=ab-suma;
//cout<<osto<<" "<<osta<<" "<<ostb<<" "<<ostab<<endl;
for(int i=1;i<=n;i++){
	if(grupa[i]=="O"){
			rez[i][1]=c[i];
	osto-=c[i];
	}
	if(osto<0){
		cout<<"nemoguce1"<<endl;
	//	return 0;
	}
}

for(int i=1;i<=n;i++){
	if(grupa[i]=="A" and osta-c[i]>=0){
			rez[i][2]=c[i];
	osta-=c[i];
	}
	else if(grupa[i]=="A" and osta>0 and osta-c[i]<0 and osto-c[i]-osta>=0){
			rez[i][1]=osto-c[i]-osta;
			rez[i][2]=osta;
			osto-=c[i];
			osta=0;
	}
	else if(grupa[i]=="A" and osta<=0 and osto-c[i]>=0){
		rez[i][1]=c[i];
	}
	else if(grupa[i]=="A" and osta<0 and osto-c[i]<0){
		cout<<"nemoguce2"<<endl;
		//return 0;
	}
}
for(int i=1;i<=n;i++){
	if(grupa[i]=="B" and ostb-c[i]>=0){
			rez[i][3]=c[i];
	ostb-=c[i];
	}
	else if(grupa[i]=="B" and ostb>0 and ostb-c[i]<0 and osto-c[i]-ostb>=0){
			rez[i][1]=osto-c[i]-ostb;
			rez[i][3]=ostb;
			osto-=c[i];
			ostb=0;
	}
	else if(grupa[i]=="B" and ostb<=0 and osto-c[i]>=0){
		rez[i][1]=c[i];
	}
	else if(grupa[i]=="B" and ostb<0 and osto-c[i]<0){
		cout<<"nemoguce3"<<endl;
		//return 0;
	}
}



for(int i=1;i<=n;i++){
	if(grupa[i]=="AB")rez[i][4]=c[i];
	ostab-=c[i];
	if(ostab<0 and osto-c[i]>=0){
		osto-=c[i];
	}
	else if(ostab<0 and osta-c[i]>=0){
		osta-=c[i];
	}
	else if(ostab<0 and ostb-c[i]>=0){
		ostb-=c[i];
	}
	else if(ostab<0 and osto-c[i]<0 and ostb-c[i]<0 and ostb-c[i]<0){
			cout<<"nemoguce4"<<endl;
		//	return 0;
}
}

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

return 0;
}