#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'){ q_cnt++; if (pos == -1) pos = j; } } if (q_cnt == 1 && W_cnt == 0) R[pos] = 'W'; cout << R << "\n"; } else { //cout << R.size() << "\n"; 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++; if (R[j] == 'W') W_cnt++; if (R[j] == '?') q_cnt++; if (q_cnt == 1 && pos == -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文字目以降になければ確定することができない */ //cout << pos << "\n"; if (q_cnt == 1){ if (K == R.size() - 1){ if (R[K] == 'W'){ R[pos] = 'W'; } else if (R[K] == 'A'){ R[pos] = 'A'; } cout << R << "\n"; continue; } 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がない->前者が確定できない以上むり? K == R.size(),K == R.size() - 1で落ちる可能性がある K == R.size()ならすべてAとなる またK = R.size() - 1なら最後の文字が決まっているときそれと同じ奴入れる これで14ケースも直るの? */ cout << R << "\n"; } } return 0; }