#include<bits/stdc++.h>

using namespace std;

int main(){
    long long n;
    cin >> n;
    long long o, a, b, ab;
    cin >> o >> a >> b >> ab;
    vector<pair<string, long long>> v(n);
    long long ans[n][4];
    memset(ans, 0, sizeof(ans));
    for(long long i = 0 ; i < n ; i++){
        cin >> v[i].first >> v[i].second;
        if(v[i].first == "O"){
            if(o >= v[i].second){
                o -= v[i].second;
                ans[i][0] = v[i].second;
                v[i].second = 0;
            }
            else{
                cout << "nemoguce";
                return 0;
            }
        }
        else if(v[i].first == "A"){
            if(a >= v[i].second){
                a -= v[i].second;
                ans[i][1] = v[i].second;
                v[i].second = 0;
            }
            else{
                ans[i][1] = a;
                v[i].second = v[i].second - a;
                a = 0;
            }
        }
        else if(v[i].first == "B"){
            if(b >= v[i].second){
                b -= v[i].second;
                ans[i][2] = v[i].second;
                v[i].second = 0;   
            }
            else{
                ans[i][2] = b;
                v[i].second = v[i].second - b;
                b = 0;
            }
        }
    }
    for(long long i = 0 ; i < n ; i++){
        if((v[i].first == "A" || v[i].first == "B") && v[i].second > 0){
            if(o >= v[i].second){
                o -= v[i].second;
                ans[i][0] = v[i].second;
                v[i].second = 0;   
            }
            else{
                cout << "nemoguce";
                return 0;
            }
        }
    }
    for(long long i = 0 ; i < n ; i++){
        if(v[i].first == "AB"){
            if(o >= v[i].second){
                o -= v[i].second;
                ans[i][0] = v[i].second;
                v[i].second = 0;   
            }
            else{
                ans[i][0] = o;
                v[i].second = v[i].second - o;
                o = 0;
            }
            if(a >= v[i].second){
                a -= v[i].second;
                ans[i][1] = v[i].second;
                v[i].second = 0;   
            }
            else{
                ans[i][1] = a;
                v[i].second = v[i].second - a;
                a = 0;
            }
            if(b >= v[i].second){
                b -= v[i].second;
                ans[i][2] = v[i].second;
                v[i].second = 0;   
            }
            else{
                ans[i][2] = b;
                v[i].second = v[i].second - b;
                b = 0;
            }
            if(ab >= v[i].second){
                ab -= v[i].second;
                ans[i][3] = v[i].second;
                v[i].second = 0;   
            }
            else{
                cout << "nemoguce";
                return 0;
            }
        }
    }

    for(long long i = 0 ; i < n ; i++){
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << "\n";
    }
    return 0;
}