#include <bits/stdc++.h>

using namespace std;

const int MAX = 10000;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin>>n;
  int io, ia, ib, iab;
  cin>>io>>ia>>ib>>iab;
  string SRes[MAX];
  int TrebaMu, TrebaMuAB[MAX], TMABCounter = 0;
  int Prima[MAX][4];
  bool IsOver = false;
  unordered_map<int, int> ABPlaces;
  for(int i = 0 ; i < n ; i++) {
    cin>>SRes[i]>>TrebaMu;
    if(!IsOver) {

      if(SRes[i] == "O") {
        if(io < TrebaMu) IsOver = true;
        io -= TrebaMu;
        Prima[i][0] = TrebaMu;
        Prima[i][1] = 0;
        Prima[i][2] = 0;
        Prima[i][3] = 0;
      }
      else if(SRes[i] == "A") {
        if(io + ia < TrebaMu) IsOver = true;
        int temp = ia;
        ia -= TrebaMu;
        if(ia < 0) {
          Prima[i][0] = TrebaMu - temp;
          io += ia;
          ia = 0;
          Prima[i][1] = temp;
        }
        else {
          Prima[i][0] = 0;
          Prima[i][1] = TrebaMu;
        }
        Prima[i][2] = 0;
        Prima[i][3] = 0;
      }
      else if(SRes[i] == "B") {
        if(io + ib < TrebaMu) IsOver = true;
        int temp = ib;
        ib -= TrebaMu;
        if(ib < 0) {
          Prima[i][0] = TrebaMu - temp;
          io += ib;
          ib = 0;
          Prima[i][2] = temp;
        }
        else {
          Prima[i][0] = 0;
          Prima[i][2] = TrebaMu;
        }
        Prima[i][1] = 0;
        Prima[i][3] = 0;
      }
      else if(SRes[i] == "AB") {
        TrebaMuAB[TMABCounter] = TrebaMu;
        ABPlaces[TMABCounter] = i;
        TMABCounter++;
      }

    }
  }

  if(IsOver) {
    cout<<"nemoguce";
    return 0;
  }

  for(int i = 0 ; i < TMABCounter ; i++) {
    if( (io + ia + ib + iab) < TrebaMuAB[i]) {
      IsOver = true;
      break;
    }
    int temp = iab;
    iab -= TrebaMuAB[i];
    int pom = ABPlaces[i];
    if(iab < 0) {
      Prima[pom][3] = temp;
      TrebaMuAB[i] -= temp;
      iab = 0;
      temp = io;
      io -= TrebaMuAB[i];
      if(io < 0) {
        Prima[pom][0] = temp;
        TrebaMuAB[i] -= temp;
        io = 0;
        temp = ia;
        ia -= TrebaMuAB[i];
        if(ia < 0) {
          Prima[pom][1] = temp;
          TrebaMuAB[i] -= temp;
          ia = 0;
          ib -= TrebaMuAB[i];
          Prima[pom][2] = TrebaMuAB[i];
        }
        else {
          Prima[pom][1] = TrebaMuAB[i];
          Prima[pom][2] = 0;
        }
      }
      else {
        Prima[pom][0] = TrebaMuAB[i];
        Prima[pom][1] = 0;
        Prima[pom][2] = 0;
      }
    }
    else {

      Prima[pom][0] = 0;
      Prima[pom][1] = 0;
      Prima[pom][2] = 0;
      Prima[pom][3] = TrebaMuAB[i];

    }
  }

  if(IsOver) cout<<"nemoguce";
  else {
    cout<<"moguce\n";
    for(int i = 0 ; i < n ; i++) {
      cout<<Prima[i][0]<<" "<<Prima[i][1]<<" "<<Prima[i][2]<<" "<<Prima[i][3]<<"\n";
    }
  }

  return 0;
}