#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

ll n, A, B, AB, O, ta[10005], tab[10005], tb[10005], to[10005];
pair<int, pair<int, int>> a[10005];

bool cmp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b){
  if(a.s.f == b.s.f){return a.s.s < b.s.s;}
  return a.s.f < b.s.f;
}

int main(){
  cin >> n;
  cin >> O >> A >> B >> AB;
  for(int i = 0; i < n; ++i){
    string str;
    a[i].f = i;
    cin >> str >> a[i].s.s;
    if(str == "O"){a[i].s.f = 0;}
    if(str == "A"){a[i].s.f = 1;}
    if(str == "B"){a[i].s.f = 2;}
    if(str == "AB"){a[i].s.f = 3;}
  }
  sort(a, a + n, cmp);
  bool can = true;
  for(int i = 0; i < n; ++i){
    ll need = a[i].s.s;
    if(a[i].s.f == 0){
      if(need >= O){can = false; break;}
      to[a[i].f] += need;
      O -= need;
    }
    else if(a[i].s.f == 1){
      if(A < need){
        ta[a[i].f] += A;
        need -= A; A = 0;
      }
      else{
        ta[a[i].f] = need;
        A -= need; need = 0;
      }
      if(O < need){
        to[a[i].f] += O;
        need -= O; O = 0;
      }else{
        to[a[i].f] += need;
        O -= need; need = 0;
      }
      if(need){
        can = false; break;
      }
    }
    else if(a[i].s.f == 2){
      if(B < need){
        tb[a[i].f] += B;
        need -= B; B = 0;
      }
      else{
        tb[a[i].f] = need;
        B -= need; need = 0;
      }
      if(O < need){
        to[a[i].f] += O;
        need -= O; O = 0;
      }else{
        to[a[i].f] += need;
        O -= need; need = 0;
      }
      if(need){
        can = false; break;
      }
    }else{
      if(AB < need){
        tab[a[i].f] += AB;
        need -= AB; AB = 0;
      }
      else{
        tab[a[i].f] = need;
        AB -= need; need = 0;
      }
      if(A < need){
        ta[a[i].f] += A;
        need -= A; A = 0;
      }
      else{
        ta[a[i].f] = need;
        A -= need; need = 0;
      }
      if(B < need){
        tb[a[i].f] += B;
        need -= B; B = 0;
      }
      else{
        tb[a[i].f] = need;
        B -= need; need = 0;
      }
      if(O < need){
        to[a[i].f] += O;
        need -= O; O = 0;
      }else{
        to[a[i].f] += need;
        O -= need; need = 0;
      }
      if(need){
        can = false; break;
      }
    }
  }
  if(!can){cout << "nemoguce" << endl; return 0;}
  cout << "moguce" << endl;
  for(int i = 0; i < n; ++i){
    cout << to[i] << " " << ta[i] << " " << tb[i] << " " << tab[i] << endl;
  }
  return 0;
}