#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O2")

// Loops
#define FOR(n)              for(int i=0;i<n;i++)
#define FORJ(n)             for(int j=0;j<n;j++)
#define FORN(n,x)           for(int x=0;i<n;i++)
#define RFOR(n)             for(int i=n-1;i>=0;i--)
#define RFORJ(n)            for(int j=n-1;j>=0;j--)
#define RFORN(n,x)          for(int x=n-1;x>=0;x--)
#define ODD_FOR(n)          for(int i=1;i<n;i+=2)
#define EVEN_FOR(n)         for(int i=2;i<n;i+=2)
#define FROM(n,m)           for(int i=n;i<m;i++)
#define FROMJ(n,m)          for(int j=n;j<m;j++)
#define RFROM(n,m)          for(int i=n-1;i>=m;i--)
#define RFROMJ(n,m)         for(int j=n-1;j>=m;j--)
#define INVERT_FOR(n)       for(int i=0,j=n-1;i<n-1 && j>0;i++,j--)
#define STL_FOR(a)          for(auto i=a.begin();i!=a.end();i++)
#define STL_FORJ(a)         for(auto j=a.begin();j!=a.end();j++)
#define STL_FORN(a,x)       for(auto x=a.begin();x!=a.end();x++)
#define STL_FROM(a,n,m)     for(auto i=n;i!=m;i++)
#define STL_FROMJ(n,m)      for(auto j=n;j!=m;j++)
#define STL_RFOR(a)         for(auto i=a.rbegin();i!=a.rend();i++)
#define STL_RFORJ(a)        for(auto j=a.rbegin();j!=a.rend();j++)
#define popcnt(n)         __builtin_popcount(n)

// Input/ Output
#define read(n) cin>>n
#define write(n) cout<<n<<'\n'
#define FAST_IO()\
ios_base::sync_with_stdio(0);\
cin.tie(0); cout.tie(0)

//Types
#define ll                 long long 
#define vec                   vector
#define veci             vector<int>
#define vi               vector<int>
#define li                 list<int>
#define arri                arr<int>
#define mati                mat<int>
#define pb                 push_back
#define pf                push_front
#define ppb                 pop_back
#define ppf                pop_front
#define umap           unordered_map
#define ummap     unordered_multimap
#define mmap                multimap
#define mset                multiset
#define uset           unordered_set
#define umset     unordered_multiset
#define INT(n)          ((int)n-'0')
#define CHAR(n)            ((char)n)

//Template classes
template<typename t_mat>
class mat
{
    size_t row_size, col_size;
    t_mat* buff;
public:
    mat()=default;
    mat(size_t row_size, size_t col_size) { this->row_size=row_size; this->col_size=col_size; buff=new t_mat[row_size*col_size];FOR(row_size*col_size)buff[i]=0;}
    ~mat() { delete[] buff; }
    inline size_t size()        const {return row_size * col_size;}
    inline size_t rowsize() const {return row_size;}
    inline size_t colsize() const {return col_size;}
    inline t_mat* operator [](int row_index) {return &buff[row_index * col_size];}
    inline const t_mat* operator [](int col_index) const {return *buff[col_index * col_size];}
    friend istream& operator>> (istream& input, mat& self) { FOR(self.size()) { input>>self.buff[i];} return input; }
    friend ostream& operator<< (ostream& output,mat& self) { FOR(self.row_size){ FORJ(self.col_size) { output<<self[i][j]<<' '; }output<<'\n'; } return output;}
};

template<typename t_arr>
class arr
{
    size_t arrsize;
    t_arr* buff;
public:
    arr()=default;
    arr(size_t arrsize) { this->arrsize=arrsize; buff=new t_arr[arrsize]; }
    ~arr() { delete[] buff; }
    inline size_t size() { return arrsize; }
    inline t_arr& operator[] (size_t index) const { return buff[index]; }
    friend istream& operator>> (istream& input,arr& self) { FOR(self.size()) { input>>self[i];}return input; }
    friend ostream& operator<< (ostream& output,arr& self) { FOR(self.size()) { output<<self[i]<<'\n'; } return output;}
};



//----------------------------------------------------------------------------------------------------------------------------------

struct wedge
{
    int edge;
    int weight;
};

class graph
{
    size_t nodecount, edgecount;
    list<wedge>* adj;
public:
    graph(size_t nodecount, size_t edgecount)
    {
        this->nodecount=nodecount;
        this->edgecount=edgecount;

        adj= new list<wedge>[nodecount+1];
    }
    ~graph()
    {
        delete[] adj;
    }
    
    inline void insert(int node, int edge, int weight)
    {
        adj[node].pb({edge, weight});
        adj[edge].pb({node, weight});
    }

    friend istream& operator>> (istream& input, graph& self)
    {
        int node, edge, weight;
        FOR(self.edgecount)
        {
            input >> node >> edge >> weight;
            self.insert(node, edge, weight);
        }

        return input;
    }

    void bfs();
    void dfs();
};



//---------------------------------------------------------------------------------------------------------------------------------------

struct ptnt
{
    int indx;
    int cnt;
};

void result()
{
    int n;
    cin>>n;
    arr<int> a(4);
    cin>>a;
    
    vec<vec<ptnt>> b(4);

    mat<int> res(n, 4);

    string l;
    int r;
    FOR(n)
    {
        cin>>l>>r;
        if(l=="O")
            b[0].pb({i, r});
        else if(l=="A")
            b[1].pb({i, r});
        else if(l=="B")
            b[2].pb({i, r});
        else
            b[3].pb({i, r});
    }

    //O blood
    FOR(b[0].size())
    {
        if(a[0]-b[0][i].cnt<0)
        {
            cout<<"nemoguce"<<endl;
            return;
        }
        else
        {
            a[0]-=b[0][i].cnt;
            res[b[0][i].indx][0] = b[0][i].cnt;
        }
    }

    //A blood
   
    FOR(b[1].size())
    {
        if(a[1]<b[1][i].cnt)
        {
            if(a[1]+a[0]<b[1][i].cnt)
            {
                cout<<"nemoguce"<<endl;
                return;
            }
            else
            {
                res[b[1][i].indx][0] = b[1][i].cnt-a[1];
                res[b[1][i].indx][1] = a[1];

                a[0]-=(b[1][i].cnt-a[1]);
                a[1]=0;
            }
        }
        else
        {
            a[1]-=b[1][i].cnt;
            res[b[1][i].indx][1]=b[1][i].cnt;
        }
        cout<<endl;
    }

    //B blood
    
    FOR(b[2].size())
    {
        if(a[2]<b[2][i].cnt)
        {
            if(a[2]+a[0]<b[2][i].cnt)
            {
                cout<<"nemoguce"<<endl;
                return;
            }
            else
            {
                res[b[2][i].indx][0] = b[2][i].cnt-a[2];
                res[b[2][i].indx][2] = a[2];

                a[0]-=(b[2][i].cnt-a[2]);
                a[2]=0;
            }
        }
        else
        {
            a[2]-=b[2][i].cnt;
            res[b[2][i].indx][2]=b[2][i].cnt;
        }
        cout<<endl;
    }

    // AB blood
    
    bool t;
    FOR(b[3].size())
    {
        t=0;
        RFORJ(4)
        {
            if(a[j]<b[3][i].cnt)
            {
                res[b[3][i].indx][j]=a[j];
                b[3][i].cnt-=a[j];
                a[j]=0;
            }
            else
            {
                t=1;
                a[j]-=b[3][i].cnt;
                res[b[3][i].indx][j]=b[2][i].cnt;
                break;
            }
        }

        if(!t)
        {
            cout<<"nemoguce"<<endl;
            return;
        }
    }

    cout<<"moguce"<<endl;
    cout<<res;
}

int main()
{
    FAST_IO();
    result();
}