#include <stdio.h>
#include<iostream>
#include <string.h>
#include <math.h>

using namespace std;

int main()
{
	int i,j=0,po=0,pom=0,x,y;
    long int ro,ra,rb,rab,n;
	char g1,g2,g3,g4,c,b;
	
	scanf("%d",&n);
	long int da[n],db[n],dog[n],dab[n],br,abr[n],abp[n];
	
	scanf("%d %d %d %d",&ro,&ra,&rb,&rab);
	printf("%d %d %d %d",ro,ra,rb,rab);
	
	i=0;
	while(i<n)
	{
		scanf("%s",&c);
		scanf("%d",&b);
		
		if(c=='O')
		{
			if(b>ro)
			{
				po=1;
			}
			else
			{
				dog[i]=b;
				da[i]=0;
				db[i]=b;
				dab[i]=0;

			}
		}
		
		else if(c=='A')
		{
			if(b<=ra)
			{
				ra=ra-b;
				dog[i]=0;
				da[i]=b;
				db[i]=0;
				dab[i]=0;
			}
			else if((ra+ro)>b)
			{
				pom=b-ra;
				da[i]=ra;
				ra=0;
				ro=ro-pom;
				dog[i]=pom;
				db[i]=0;
				dab[i]=0;
			}
			else if((ra+ro)<b)
			{
				po=1;
			}
		}
		
		else if(c=='B')
		{
			if(b<=rb)
			{
				rb=rb-b;
				dog[i]=0;
				db[i]=b;
				da[i]=0;
				dab[i]=0;
			}
			else if((rb+ro)>b)
			{
				pom=b-rb;
				db[i]=rb;
				rb=0;
				ro=ro-pom;
				dog[i]=pom;
				da[i]=0;
				dab[i]=0;
			}
			else if((rb+ro)<b)
			{
				po=1;
			}
		}
		
		else if(c=='AB')
		{
			abr[j]=i;
			abp[j]=b;
			j++;
		}
		
	i++;
	}
	i=0;
	while(i<j)
	{
		x=abr[i];
		y=abp[i];
		if(rab>y)
		{
			rab=rab-y;
			dog[x]=0;
			db[x]=0;
			da[x]=0;
			dab[x]=y;
			
		}
		else if((rab+rb+ra+ro)>y)
		{
			pom=y-rab;
			dab[x]=rab;
			rab=0;
			
			if(rab<=(y-dab[x]))
			{
				pom=pom-rab;
				dab[x]=rab;
				rab=0;
			}
			else if(rb>(y-dab[x]))
			{
				dab[x]=y;
				rab=rab;
			}
			pom=rb-pom;
			rb=rb-pom;
			dog[x]=0;
			db[x]=0;
			da[x]=0;
			
		}

	}
	return 0;
}