#include <iostream>
#include <cstring>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv){
	
//C=AB
	int n,o,a,b,ab,i,br,j,osuma=0,asuma=0,bsuma=0,absuma=0,suma;
	
	scanf("%d",&n);

	char k[10];
	
	scanf("%d %d %d %d",&o,&a,&b,&ab);
	
	for(i=0;i<n;i++)
	{
		scanf("%s",k); scanf("%d",&br);
		for(j=0;j<strlen(k);j++)
		{
			if(k[j]=='O'){ osuma+=br;}
		else{
			if(k[j]=='C'){ absuma+=br;}
			else{
			if(k[j]=='B'){ bsuma+=br;}
			else{ asuma+=br;}
		}
		}
		}
	}


if(osuma>o || asuma>a+(o-osuma) || bsuma>b+((o-osuma)-(asuma-a)) || absuma>a+b+ab+o || absuma>((a-asuma)+(b-bsuma)+ab+(o-osuma-(a-asuma)-(b-bsuma)))) { printf("nemoguce");}

else{ printf("moguce\n");

	if(osuma<=o && osuma>0){  o-=osuma; printf("%d000\n",osuma);}
	
	if(asuma<=a && asuma>0){ a-=asuma; printf("0%d00\n",asuma);
	}else {
		if(asuma>a && asuma<=a+o){ o-=asuma-a;  printf("%d%d00\n",asuma-a,a);
		}
	}

if(bsuma<=b && bsuma>0){ b-=bsuma; printf("00%d0\n",bsuma);
	}else {
		if(bsuma>b && bsuma<=b+o){ o-=bsuma-b;  printf("%d0%d0\n",bsuma-b,b);
		}
	}

	if(absuma<=ab && absuma>0){ printf("000%d\n",absuma);	}

	else{
		
		if(absuma>ab && absuma<=ab+o+a+b){ absuma-=ab; 
		if(absuma<=o){ printf("%d00%d\n",absuma,ab);}
		else{
			if(absuma>o && absuma<=o+a){ absuma=absuma-(a+o); printf("%d%d0%d\n",o,absuma,ab); }
			else{
				
				if(absuma>o+a && absuma<=o+a+b){  printf("%d%d%d%d\n",o,a,absuma-b,ab); }
			}
		}
			}
			
		
		
}
		}	}