#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define MAXN 10010

using namespace std;

int n, o, a, b, ab;
string s[MAXN];
int k[MAXN], ress[MAXN][5];

void ne()
{
    cout<<"nemoguce"; exit(0);
}

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

    cin>>n;
    cin>>o>>a>>b>>ab;

    for (int i=0; i<n; i++)
        cin>>s[i]>>k[i];

    for (int i=0; i<n; i++)
    {
        if (s[i]=="O") { ress[i][0]+=k[i]; o-=k[i]; k[i]=0; }
    }
    if (o<0) ne();

    for (int i=0; i<n; i++)
    {
        if (s[i]=="A")
        {
            if (a) { ress[i][1]+=min(k[i], a); int pom=k[i]; k[i]-=min(k[i], a); a=max(0, a-pom); }
            if (k[i]) { ress[i][0]+=k[i]; o-=k[i]; k[i]=0; }
        }
    }
    if (o<0) ne();

    for (int i=0; i<n; i++)
    {
        if (s[i]=="B")
        {
            if (b) { ress[i][2]+=min(k[i], b); int pom=k[i]; k[i]-=min(k[i], b); b=max(0, b-pom); }
            if (k[i]) { ress[i][0]+=k[i]; o-=k[i]; k[i]=0; }
        }
    }
    if (o<0) ne();

    for (int i=0; i<n; i++)
    {
        if (s[i]=="AB")
        {
            if (a) { ress[i][1]+=min(k[i], a); int pom=k[i]; k[i]-=min(k[i], a); a=max(0, a-pom); }
            if (b) { ress[i][2]+=min(k[i], b); int pom=k[i]; k[i]-=min(k[i], b); b=max(0, b-pom); }
            if (ab) { ress[i][3]+=min(k[i], ab); int pom=k[i]; k[i]-=min(k[i], ab); ab=max(0, ab-pom); }
            if (k[i]) { ress[i][0]+=k[i]; o-=k[i]; k[i]=0; }
        }
    }
    if (o<0) ne();

    cout<<"moguce"<<endl;
    for (int i=0; i<n; i++) cout<<ress[i][0]<<" "<<ress[i][1]<<" "<<ress[i][2]<<" "<<ress[i][3]<<endl;

}