#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ar array

#define ff first 
#define ss second 
#define mp make_pair

#define vt vector
#define pb push_back

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

#define en '\n'
#define sp ' '
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b); int _temp = max(a, b); b = min(a, b); a = _temp;
#define bit_count(a) __builtin_popcount(a)

#define rep(i,n) for(auto i=0; i<(n); i++) 
#define EACH(x, a) for (auto& x: a)

#define all(x) (x).begin(), (x).end() 
#define sz(x) (int)(x).size()

using namespace std;

typedef  map<string,int>         msi; 
typedef  map<int,int>	         mii; 
typedef  map<ll, ll>             mll; 
typedef  map<char,int>           mci; 
typedef  map<int,string>	     mis; 
typedef  pair<int,int> 	         pii;
typedef  pair<ll, ll> 	         pll;  
typedef  pair<string, int>       psi; 
typedef  pair<string, string>    pss; 
typedef  vector<int> 	         vi;  
typedef  vector<string> 	     vs; 
typedef  vector<char>	         vc; 
typedef  vector<bool>            vb; 
typedef  vector< pii >           vii;
typedef  vector< ll >            vll;
typedef  vector<pii>             vpii;
typedef  vector<pll>             vpll;
typedef  vector<vi>              vvi;
typedef  vector<vll>             vvll;


template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}

template<class A> void read(vt<A>& x) {
	EACH(a, x)
		read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
	EACH(a, x)
		read(a);
}
 
template<class H, class... T> void read(H& h, T&... t) {
	read(h);
	read(t...);
}

string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b?"true":"false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vt<bool> v) {
	string res;
	FOR(sz(v))
		res+=char('0'+v[i]);
	return res;
}
 
template<size_t S> string to_string(bitset<S> b) {
	string res;
	FOR(S)
		res+=char('0'+b[i]);
	return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
		if(!f)
			res+=' ';
		f=0;
		res+=to_string(x);
	}
    return res;
}

template<class A> void write(A x) {
	cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) { 
	write(h);
	write(t...);
}
void print() {
	write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) { 
	write(h);
	if(sizeof...(t))
		write(' ');
	print(t...);
}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

const ll LINF = 1e15;
const int mxN = 2e5+10, INF = 1e9, MOD = 1e9+7, mod = 998244353;

void solve(){
    int n;
    read(n);
    int o,a,b,ab;
    read(o,a,b,ab);
    vt<pair<string,int>> v(n);
    FOR(n){
        read(v[i].ff,v[i].ss);
    }
    vt<array<int,4>> ans(n);

    FOR(n){
        int x = v[i].ss;
        if(v[i].ff=="O"){
            if(o>=x){
                o-=x;
                ans[i][0]=x;
            } else{
                print("nemoguce");
                return;
            }
        }
    }

    FOR(n){
        int x = v[i].ss;
        if(v[i].ff=="A"){
            if(a>=x){
                a-=x;
                ans[i][1]=x;
                x=0;
            }
            if(x-a>0){
                x-=a;
                ans[i][1]=a;
                a=0;
            }
            if(x>0){
                if(o>=x){
                    o-=x;
                    ans[i][0]=x;
                    x=0;
                } else{
                    print("nemoguce");
                    return;
                }
            }
        }

        if(v[i].ff=="B"){
            if(b>=x){
                b-=x;
                ans[i][2]=x;
                x=0;
            }
            if(x-b>0){
                x-=b;
                ans[i][2]=b;
                b=0;
            }
            if(x>0){
                if(o>=x){
                    o-=x;
                    ans[i][0]=x;
                    x=0;
                } else{
                    print("nemoguce");
                    return;
                }
            }
        }
    }

    vt<int> vr(4);
    vr[0]=o;
    vr[1]=a;
    vr[2]=b;
    vr[3]=ab;
    int j=3;
    FOR(n){
        if(v[i].ff=="AB"){
            int x=v[i].ss;
            while(x>0&&j>=0){
                if(vr[j]>=x){
                    vr[j]-=x;
                    ans[i][j]=x;
                    x=0;
                } else{
                    x-=vr[j];
                    ans[i][j]=vr[j];
                    vr[j]=0;
                }
                if(vr[j]==0) j--;
            }
            if(x>0){
                print("nemoguce");
                return;
            }
        }
    }

    print("moguce");
    FOR(n){
        print(ans[i][0], ans[i][1], ans[i][2], ans[i][3]);
    }
}

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

    int tc=1;
    cin>>tc;
    while(tc--){
        solve();
    }
    return 0;
}