#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 { 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++; if (R[j] == 'W') W_cnt++; if (R[j] == '?') q_cnt++; if (pos == -1 && q_cnt == 1) pos = j; } if (W_cnt != 0){ cout << R << "\n"; continue; //Wが最初のK文字にあったら終了 } 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'; } cout << R << "\n"; continue; } // ここの時点で最初のK文字はAと?両方で構成されている奴だけ残る else { if (K == R.size()){ cout << R << "\n"; continue; } /* ココから調べること 最初のK文字はAと?で構成されていて、K != R.size()であるから最初のK文字目にWが混合しているかと K+1文字目以降がすべてAであるかを調べる K文字目までに?が1個ならK+1文字目以降にwがあればW確定。AだけしかなかったらA確定。Wが無くて?があったら終了 ?が2個以上あったら終了 */ if (q_cnt >= 2){ cout << R << "\n"; continue; } else if (q_cnt == 1){ if (W_cnt >= 1){ R[pos] = 'W'; cout << R << "\n"; continue; } else { bool flag = false; for (int j = K; j < int(R.size()); j++){ if (R[j] == '?') flag = true; } if (flag){ cout << R << "\n"; continue; } else { R[pos] = 'A'; cout << R << "\n"; continue; } } } } } } return 0; }