#include<stdio.h>

void dodeli(int p[4], int kolicina)
{
  int o = 0, a = 0, b = 0, ab = 0;
  
  if(p[0] > kolicina)
  {
    p[0] -= kolicina;
    o = kolicina;
    kolicina = 0;
  }
  else
  {
    kolicina -= p[0];
    o = p[0];
    p[0] = 0;
  }

  if(p[1] > kolicina)
  {
    p[1] -= kolicina;
    a = kolicina;
    kolicina = 0;
  }
  else
  {
    kolicina -= p[1];
    a = p[1];
    p[1] = 0;
  }

  if(p[2] > kolicina)
  {
    p[2] -= kolicina;
    b = kolicina;
    kolicina = 0;
  }
  else
  {
    kolicina -= p[2];
    b = p[2];
    p[2] = 0;
  }

  if(p[3] > kolicina)
  {
    p[3] -= kolicina;
    ab = kolicina;
    kolicina = 0;
  }
  else
  {
    kolicina -= p[3];
    ab = p[3];
    p[3] = 0;
  }


  printf("%d %d %d %d\n", o, a, b, ab);
}

int main()
{
    int n;
    int o, a, b, ab;
    int oS = 0, aS = 0, bS = 0, abS = 0;
    int p[4][4];
    int kolicina[10050];
    char tip[10050];

    scanf("%d", &n);
    scanf("%d%d%d%d", &o, &a, &b, &ab);

    scanf("%c", &tip[0]);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            p[0][j] = 0;
            p[1][j] = 0;
            p[2][j] = 0;
            p[3][j] = 0;
        }
        
        char tip1, dump;

        scanf("%c", &tip[i]);
        scanf("%c", &tip1);
        scanf("%d%c", &kolicina[i], &dump);

        if(tip1 == 'B')
        {
            tip[i] = 'C';
            abS += kolicina[i];
        }
        else if(tip[i] == 'O')
            oS += kolicina[i];
        else if(tip[i] == 'A')
            aS += kolicina[i];
        else if(tip[i] == 'B')
            bS += kolicina[i];
    }


    if(oS > o)
    {
        printf("nemoguce");
        return 0;
    }
    p[0][0] = oS;
    o -= oS;


    if(bS > o + b)
    {
        printf("nemoguce");
        return 0;
    }
    if(b >= bS)
    {
        p[2][2] = bS;
        b -= bS;
    }
    else
    {
        p[2][2] = b;
        bS -= b;
        o -= bS;
        p[2][0] = bS;
    }


    if(aS > o + a)
    {
        printf("nemoguce");
        return 0;
    }
    if(a >= aS)
    {
        p[1][1] = aS;
        a -= aS;
    }
    else
    {
        p[1][1] = a;
        aS -= a;
        o -= aS;
        p[1][0] = aS;
    }


    if(abS > o + a + b + ab)
    {
        printf("nemoguce");
        return 0;
    }
    if(ab >= abS)
        p[3][3] = abS;
    else
    {
        p[3][3] = ab;
        abS -= ab;

        if(b > abS)
        {
            p[3][2] = abS;
            abS = 0;
        }
        else
        {
            p[3][2] = b;
            abS -= b;
        }

        if(a > abS)
        {
            p[3][1] = abS;
            abS = 0;
        }
        else
        {
            p[3][1] = a;
            abS -= a;
        }

        p[3][0] = abS;
    }


    printf("moguce\n");
    for(int i = 0; i < n; i++)
    {
      if(tip[i] == 'O')
        dodeli(p[0], kolicina[i]);
      if(tip[i] == 'A')
        dodeli(p[1], kolicina[i]);
      if(tip[i] == 'B')
        dodeli(p[2], kolicina[i]);
      if(tip[i] == 'C')
        dodeli(p[3], kolicina[i]);
    }


}