#include <bits/stdc++.h>

using namespace std;

#define xx first
#define yy second
#define up upper_bound
#define lp lower_bound
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
const int MAX=10e9;
int n;
int niz[4];
int res[10007][4];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    cin>>niz[0]>>niz[1]>>niz[2]>>niz[3];
    vector<pii> v;
    for(int i=0;i<n;i++)
    {
        str s;
        int m;
        cin>>s>>m;
        int ind;
        if(s=="O")
            ind=0;
        else if(s=="A")
            ind=1;
        else if(s=="B")
            ind=2;
        else if(s=="AB")
            ind=3;
        for(int j=ind;j>=0;j--)
        {
            if(ind==2 && j==1)
            {
                continue;
            }
            if(m<niz[j])
            {
                res[i][j]=m;
                niz[j]-=m;
                m=0;
            }
            else
            {
                res[i][j]=niz[j];
                m-=niz[j];
                niz[j]=0;
            }
        }
        if(m!=0)
        {
            cout<<"nemoguce";
            return 0;
        }
    }
    cout<<"moguce"<<endl;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<4;j++)
        {
            cout<<res[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}