#include #include #include using namespace std; using namespace atcoder; using ll = long long; //#define endl "\n"; int main(){ ll Q; cin >> Q; for(int q = 1; q <= Q; q++){ string R, S; cin >> R; cin >> S; ll K; cin >> K; ll w = 0; for(ll i = 0; (ll)i < R.size(); i++){ if(R[i] == 'W') w++; } if(S == "Warong"){ //最初のK文字がA for(ll i = 0; i < K; i++) R[i] = 'A'; if(w == 0){ ll cnt = 0; for(ll i = 0; i < (ll)R.size(); i++) if(R[i] == '?') cnt++; if(cnt == 1){ //?が1個だけならW確定 for(ll i = 0; i < (ll)R.size(); i++) if(R[i] == '?') R[i] = 'W'; } cout << R << endl; }else{ cout << R << endl; } }else{ //K文字Aが続かなければよい ll cnt = 0, cntw = 0; for(ll i = 0; i < min(K, (ll)R.size()); i++){ if(R[i] == '?') cnt++; if(R[i] == 'W') cntw++; } if(cnt == 1 && cntw == 0){ //?が1個だけならW確定 for(ll i = 0; i < min(K, (ll)R.size()); i++) if(R[i] == '?') R[i] = 'W'; cout << R << endl; }else{ cout << R << endl; } } } return 0; }