#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int zaliheO,zaliheA,zaliheB,zaliheAB;
    cin >> zaliheO>>zaliheA>>zaliheB>>zaliheAB;
    string grupa[n];
    int jedinica[n];
    int dodO=0,dodA=0,dodB=0,dodAB=0;
    for(int i=0;i<n;i++)
    cin >> grupa[i] >> jedinica[i];
   for(int i=0;i<n;i++){
    if(grupa[i]=="O"){
            if(zaliheO>0 && dodO <=jedinica[i]){
        zaliheO =zaliheO - 1;
        dodO+=1;

        }
        cout<< dodO<<" ";
        cout<< dodA<<" ";
        cout<< dodB<<" ";
        cout<< dodAB<<endl;
        }
    if(grupa[i]=="A"){
        if(zaliheA>0 && dodA<=jedinica[i] && dodA<=zaliheA && dodO <=jedinica[i]){
        if(zaliheA>zaliheO){
            zaliheA-=1;
            dodA +=1;
            }}
            else
        if(zaliheO>0 && dodO<=zaliheO && dodO<=zaliheO)
            {
            zaliheO-=1;
            dodO +=1;
            }
            cout<< dodO <<" ";
        cout<< dodA<<" ";
        cout<< dodB<<" ";
        cout<< dodAB<<endl;
            }
    if(grupa[i]=="B"){
    if(zaliheB>0 && dodB<=jedinica[i] && dodB<=zaliheB && dodO <=jedinica[i]){
            if(zaliheB>zaliheO){
            zaliheB-=1;
            dodB+=1;

            }}
        else
        if(zaliheO>0 && dodO<=jedinica[i]&& dodO<=zaliheO){
            zaliheO-=1;
            dodO+=1;
            }
            cout<< dodO <<" ";
        cout<< dodA<<" ";
        cout<< dodB<<" ";
        cout<< dodAB<<endl;
    }
    if(grupa[i]=="AB")
        {
        if(zaliheAB>0 &&  dodAB<=jedinica[i]&& dodAB<=zaliheAB && dodO <=jedinica[i] && dodA <=jedinica[i] && dodB <=jedinica[i]){
        if(zaliheAB==max(zaliheAB,max(zaliheB,max(zaliheA,zaliheO))))
            {
            zaliheAB-=1;
            dodAB+=1;
            }}
            else
                if(zaliheB>0 && dodB<=jedinica[i] && dodB<=zaliheB && dodO <=jedinica[i]){
            if(zaliheB == max(zaliheB,max(zaliheA,zaliheO)) )
                {
            zaliheB-=1;
            dodB+=1;

                }}
            else
            if(zaliheA>0 && dodA<=jedinica[i] && dodA<=zaliheA && dodO <=jedinica[i]){
                if(zaliheA == max(zaliheA,zaliheO)){
                zaliheA -=1;
                dodA +=1;

                }}
                else
                if(zaliheO>0&& dodO<=jedinica[i] && dodO<=zaliheO){
                zaliheO -=1;
                dodO+=1;
                }
            else
                cout<<"nemoguce"<< endl;
cout<< dodO<<" ";
        cout<< dodA<<" ";
        cout<< dodB<<" ";
        cout<< dodAB<<endl;
        }
}

return 0;

}