#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 = 0;; for (int j = K; j <= int(R.size()); j++){ if (R[j] == 'W'){ W_cnt++; } } 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; 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 (q_cnt == 1) pos = j; } if (A_cnt == K){ for (int j = K; j < int(R.size()); j++){ if (R[j] == '?') R[j] = 'A'; } cout << R << "\n"; continue; } // K文字目までにWがあるとそこで終了 if (W_cnt != 0){ cout << R << "\n"; continue; } //この時点でK文字目まではAか?になっていることが確定 //Notだから?が1個ならそこにW入れて終わり //後ろによりそう /* q_cnt == 1,WがK文字目までに出現しないとき K + 1文字目以降にWある K文字目までにあるただ一つの?はWで確定 K+1文字目以降になければ確定することができない */ if (q_cnt == 1){ W_cnt = 0; for (int j = K; j < int(R.size()); j++){ if (R[j] == 'W') W_cnt++; } if (W_cnt != 0){ R[pos] = 'W'; } cout << R << "\n"; continue; } //K文字目までに?二個以上確定。後ろを調べる /* ここからどうするか A???? N 3 とする K文字目までにW混入->確定できない Wがない->前者が確定できない以上むり? */ cout << R << "\n"; } } return 0; }