#include <bits/stdc++.h>
    using namespace std;
    int resenje[10010] [4];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N; cin >> N;
    long long A , B , O , AB;
    cin >> O >> A >> B >> AB;
    queue<pair<int,long long> > Nereseno; 
    string X; 
    long long y; 
    for(int i = 0; i < N; i++)
    { 
        cin >> X >> y;
        if(X == "O")
        { 
            if(y <=O)
            { 
                resenje[i] [0] = y;
                O = O - y; 
            } 
            else
            { 
                cout << "nemoguce" << endl;
                return 0;
            }
        }
        else if(X == "A")
        { 
            if(y <= A)
            { 
                resenje[i] [1] = y;
                A = A - y; 
            } 
            else 
            { 
                y = y - A;
                resenje[i] [1] = A;
                A = 0;
                if(y <=O)
                { 
                resenje[i] [0] = y;
                O = O - y; 
                } 
                else
                { 
                cout << "nemoguce" << endl;
                return 0;
                }
            }
        }
        else if(X == "B")
        { 
            if(y <= B)
            { 
                resenje[i] [2] = y;
                B = B - y; 
            } 
            else 
            { 
                y = y - B;
                resenje[i] [2] = B;
                B = 0;
                if(y <=O)
                { 
                resenje[i] [0] = y;
                O = O - y; 
                } 
                else
                { 
                cout << "nemoguce" << endl;
                return 0;
                }
            }
        }
        else if(X == "AB")
        { 
            if(y <= AB)
            { 
                resenje[i][3] = y;
                AB = AB - y;
            }
            else
            { 
                y = y - AB;
                resenje[i][3] = AB;
                AB = 0;
                Nereseno.push(make_pair(i,y));
            }
        }
    }
    while(!Nereseno.empty())
    { 
        if(Nereseno.front().second > 0)
        { 
            int diff = min(O , Nereseno.front().second);
            resenje[Nereseno.front().first][0] = diff;
            Nereseno.front().second -= diff;
            O -= diff;
        } 
        if(Nereseno.front().second > 0)
        { 
            int diff = min(A , Nereseno.front().second);
            resenje[Nereseno.front().first][1] = diff;
            Nereseno.front().second -= diff;
            A -= diff;
        } 
        if(Nereseno.front().second > 0)
        { 
            int diff = min(B , Nereseno.front().second);
            resenje[Nereseno.front().first][2] = diff;
            Nereseno.front().second -= diff;
            B -= diff;
        } 
        if(Nereseno.front().second > 0)
        { 
            cout << "nemoguce" << endl;
            return 0;
        }
        Nereseno.pop(); 
    }

    cout << "moguce" << endl;
    for(int i = 0; i < N; i ++)
    { 
        for(int j = 0; j < 3; j++)
            cout << resenje[i][j] << " ";
            cout << resenje[i] [3] << endl;
    }


    
    return 0;
}