#include <iostream>
using namespace std;
int main()
{
int N;
long long O,A,B,AB,zalihe,potrebe;
long long pO,pA;
cin>>N;
cin>>O>>A>>B>>AB;
zalihe = O+A+B+AB;
potrebe = 0;
pO = 0;
pA = 0;
string g[N];
long long brj[N];
for(int i=0;i<N;i++){
cin>>g[i]>>brj[i];
potrebe +=brj[i];
if (g[i]=="O"){
pO += brj[i];
}
if (g[i]=="A"){
pA += brj[i];
}
}
if (potrebe>zalihe){
cout<<"nemoguce";
}
else{
long long a[N][4];
long long tmpO = O - pO;
long long tmpA = A;
if ((B==0)&&(AB==0)&&(pO<=O)&&(zalihe - pO >= pA)){
for(int i=0;i<N;i++){
if (g[i]=="O"){
a[i][0]=brj[i];
a[i][1]=0; a[i][2]=0;a[i][3]=0;
}
if((g[i]=="B")||(g[i]=="AB")){
a[i][0]=0; a[i][1]=0; a[i][2]=0; a[i][3]=0;}
if(g[i]=="A"){
// rasporediti sve sto je ostalo na A
if (tmpA>=brj[i]){
a[i][0]=0; a[i][1]=brj[i]; a[i][2]=0; a[i][3]=0;
tmpA = tmpA - brj[i];
}
else {
a[i][0]=brj[i]-tmpA; a[i][1]=tmpA; a[i][2]=0; a[i][3]=0;
tmpO = tmpO - brj[i]-tmpA;
}
}

}
cout<<"moguce"<<endl;
for (int i = 0; i < N; i++) {
      for (int j = 0; j < 4; j++)
        printf("%lld ", a[i][j]);
      printf("\n");
}
}
else{
cout<<"nemoguce";

}
      
}
}