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

using namespace std;

int main()
{
    int N;
    scanf("%d", &N);
    int zalihe[4];
    int uk[N]; //potrebe
    string gr[N]; //grupe
    int krv[N][4]; //ko prima sta

    for(int i=0; i<4; i++)
        cin >> zalihe[i];
    for(int i=0; i<N; i++)
        cin >> gr[i] >> uk[i];

    for(int i=0; i<N; i++)
        for(int j=0; j<4; j++)
            krv[i][j] = 0;


    for(int i=0; i<N; i++)
    {
        if (gr[i]=="O")
        {
            if (uk[i]>zalihe[0])
            {
                printf("nemoguce");
                return 0;
            }
            krv[i][0] += uk[i];
            zalihe[0] -= uk[i];
        }

        else if (gr[i]=="A")
        {
            if (zalihe[1] == 0)
                continue;
            if(uk[i]>zalihe[1] && zalihe[1]>0)
            {
                krv[i][1] += zalihe[1];
                zalihe[1] = -i;
            }
            else
            {
                krv[i][1] += uk[i];
                zalihe[1] -= uk[i];
            }
        }

        else if (gr[i]=="B")
        {
            if (zalihe[2] == 0)
                continue;
            if(uk[i]>zalihe[2] && zalihe[2]>0)
            {
                krv[i][2] += zalihe[2];
                printf("  %d  ", krv[i][2]);
                zalihe[2] = -i;
            }
            else
            {
                krv[i][2] += uk[i];
                zalihe[2] -= uk[i];
            }
        }

        else
        {
            if(zalihe[3] == 0)
                continue;
            if(uk[i]>zalihe[3])
            {
                krv[i][3] += zalihe[3];
                zalihe[3] = -i;
            }
            else
            {
                krv[i][3] += uk[i];
                zalihe[3] -= uk[i];
            }
        }

    }

    if(zalihe[3]<0 && zalihe[1]>0)
        for(int i=zalihe[3]; i<N; i++)
            if (gr[i]=="AB")
            {
                krv[i][1] += min(zalihe[1],uk[i]-krv[i][3]);
                zalihe[1] -= min(zalihe[1],uk[i]-krv[i][3]);
                if (zalihe[1] == 0)
                {
                   zalihe[1] = -i;
                   break;
                }
            }

    if(zalihe[3]<0 && zalihe[1]<0 && zalihe[2]>0)
        for(int i=zalihe[1]; i<N; i++)
            if (gr[i]=="AB")
            {
                krv[i][1] += min(zalihe[2],uk[i]-krv[i][3]);
                zalihe[1] -= min(zalihe[2],uk[i]-krv[i][3]);
                if (zalihe[2] == 0)
                {
                   zalihe[2] = -i;
                   break;
                }
            }


    for(int i=0; i<N; i++)
        if (krv[i][0]+krv[i][1]+krv[i][2]+krv[i][3]<uk[i])
        {
            krv[i][0] += uk[i]-(krv[i][0]+krv[i][1]+krv[i][2]+krv[i][3]);
            zalihe[0] -= uk[i]-(krv[i][0]+krv[i][1]+krv[i][2]+krv[i][3]);
            if (zalihe[0]<0)
            {
                printf("nemoguce");
                return 0;
            }
        }


printf("moguce\n");
for(int i=0; i<N; i++, printf("\n"))
    for(int j=0; j<4; j++)
        printf("%d ",krv[i][j]);
printf("\n");
for(int i=0; i<4; i++)
    printf("%d ", zalihe[i]);
return 0;
}