#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int oy[3], ay[3], by[3], aby[3];
    int n, a, b, o, ab, pj, i;
    string kg;
    cin >> n >> o >> a >> b >> ab;
    for ( i = 1; i <= n; i++ )
         {
              cin >> kg >> pj;
              if ( kg == "O" )
                 o -= pj;
              if ( kg == "A" )
                 a -= pj;
              if ( kg == "B" )
                 b -= pj;
              if ( kg == "AB" )
                 ab -= pj;
              if ( ab < 0 )
                  {
                      aby[i] = ab + pj;
                      if ( b >= pj + ab )
                         {
                             b -= pj + ab;
                             by[i] = pj + ab;
                         }
                      if ( a >= pj + ab )
                         a -= pj + ab;
                         ay[i] = pj + ab;
                      ab = 0;
                  }
              if ( a < 0 )
                  {
                      ay[i] = a + pj;
                      oy[i] = -a;
                      o -= oy[i];
                      a = 0;
                  }
              if ( b < 0 )
                  {
                      by[i] = b + pj;
                      oy[i] = -b;
                      o -= oy[i];
                      b = 0;
                  }
              if ( o < 0)
                  {
                      cout << "nemoguce";
                      return 0;
                  }
         }
    cout << "moguce" << endl;
    for ( i = 1; i <= n; i++ )
        cout << oy[i] << " " << ay[i] << " " << by[i] << " " << aby[i] << endl;
    return 0;
}