#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int n,o,a,b,ab,i,k[100],p;
	char l[100];
	printf("unesi broj pacijena\n");
	scanf("%d",&n);
	printf("unesi broj jedinica krvne grupa o,a,b i ab (krvnu grupu ab obelezit slovom p)\n");
	scanf("%d%d%d%d",&o,&a,&b,&ab);
	for(i=0;i<n;i++)
		{
			printf("koja je krvna grupa %d. pacijenta i koliko mu je jedinica krvi potrebno:\n",i+1);
			scanf(" %c%d",&l[i],&k[i]);
		}
	printf("resenje\n");
	for(i=0;i<n;i++)
		{
			if(l[i]=='o' && k[i]<=o)
				{
					printf("%d 0 0 0\n",k[i]);
					o=o-k[i];
				}
			else if(l[i]=='o' && k[i]>o)
				{
					printf("nemoguce");
					break;
				}
			if(l[i]=='a' && k[i]<=a)
				{
					printf("0 %d 0 0\n",k[i]);
					a=a-k[i];
				}
			else if(l[i]=='a' && k[i]<=a+o)
				{
					printf("%d %d 0 0\n",k[i]-a,a);
					o=o-(k[i]-a);
					a=0;
				}
			else if(l[i]=='a' && k[i]>a+o)
				{
					printf("nemoguce");
					break;
				}
			if(l[i]=='b' && k[i]<=b)
				{
					printf("0 0 %d 0\n",k[i]);
					b=b-k[i];
				}
			else if(l[i]=='b' && k[i]<=b+o)
				{
					printf("%d 0 %d 0\n",k[i]-b,b);
					o=o-(k[i]-b);
					b=0;
				}
			else if(l[i]=='b' && k[i]>b+o)
				{
					printf("nemoguce");
					break;
				}
			if(l[i]=='p' && k[i]<=ab)
				{
					printf("0 0 0 %d\n",k[i]);
					ab=ab-k[i];
				}
			else if(l[i]=='p' && k[i]<=ab+o)
				{
					printf("%d 0 0 %d\n",k[i]-ab,ab);
					o=o-(k[i]-ab);
					ab=0;
				}
			else if(l[i]=='p' && k[i]<=ab+o+a)
				{
					printf("%d %d 0 %d\n",o,k[i]-ab-o,ab);
					a=a-(k[i]-ab-o);
					o=0;
					ab=0;
				}
			else if(l[i]=='p' && k[i]<=ab+o+a+b)
				{
					printf("%d %d %d %d\n",o,a,k[i]-ab-o-a,ab);
					b=b-(k[i]-ab-o-a);
					o=0;
					a=0;
					ab=0;
				}
			else if(l[i]=='p' && k[i]>ab+o+a+b)
				{
					printf("nemoguce");
					break;
				}
		}		
	
	return 0;
}