#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* Warong:WがK+1文字目以降にあってK文字目までは全部A Not:Warongを満たさない(K+1文字目以降にWがないか最初のK文字にWが混ざっている) WarongならRのK文字目までで?があったらAにする、K+1文字目以降でWがなく、?が一つだけなら?をWにする NotならK文字目まで全部Aを満たしていたらK+1文字目以降の?はすべてA、 K+1文字目以降にWが混ざっていたらK文字目までで?が一つでWがなければ?をWにする */ int main(){ long long T; cin >> T; for (int i = 0; i < T; i++){ string R,S; int K; cin >> R >> S >> K; if (S[0] == 'W'){ for (int j = 0; j < K; j++){ if (R[j] == '?') R[j] = 'A'; } int q_cnt = 0,W_cnt = 0,pos = -1;; for (int j = K; j <= int(R.size()); j++){ if (R[j] == 'W'){ W_cnt++; } if (R[j] == '?'){ q_cnt++; if (q_cnt == 1 && pos == -1) pos = j; } } if (q_cnt == 1 && W_cnt == 0) R[pos] = 'W'; cout << R << "\n"; } else { if (K == R.size()){ for (int j = 0; j < R.size(); j++){ if (R[j] == '?')R[j] = 'A'; } cout << R << "\n"; continue; } int A_cnt = 0, W_cnt = 0, q_cnt = 0,pos = -1; for (int j = 0; j < K; j++){ if (R[j] == 'A') A_cnt++; } for (int j = K; j < int(R.size()); j++){ if (R[j] == 'W'){ W_cnt++; } } if (A_cnt == K){ for (int j = K; j < int(R.size()); j++){ if (R[j] == '?') R[j] = 'A'; } } else { if (W_cnt > 0){ W_cnt = 0; for (int j = 0; j < K; j++){ if (R[j] == 'W') W_cnt++; if (R[j] == '?'){ q_cnt++; if (q_cnt == 1 && pos == -1) pos = j; } } if (W_cnt == 0 && q_cnt == 1) R[pos] = 'W'; } } cout << R << "\n"; } } return 0; }