#include #include //cin/cout #include //cout string #include //rambda #include #include //next/prev #include #include //iota #include #include #include #include #include #include #include using namespace atcoder; using namespace std; using llong = long long; const llong INF = 1LL << 60;//INF > 10^18(1e18) const int INF32 = 1LL << 30;//INF32 > 10^9(1e9) template bool chmax(T& max, const T& b) { if (max >= b) return false; max = b; return true; } template bool chmin(T& min, const T& b) { if (min <= b) return false; min = b; return true; } ///////////////////ここまでtoolbox///////////////////////////////////// string solve() { string R,S; cin >> R; int N = R.size(); cin >> S; int K; cin >> K; if (S == "NotWarong") { //最初のK文字のどこかにWがある //あるいは、全てAである int acount = 0; int qcount = 0; for (int k = 0; k < K; k++) { if (R[k] == 'A') { acount++; } if (R[k] == '?') { qcount++; } } bool wrong = false; bool ac = true; for (int n = K; n < N; n++) { if (R[n] == 'W') { wrong = true; } if (R[n] != 'A') { ac = false; } } //①最初のK文字が全てAのとき //全てAが答え if (acount == K) { for (int n = 0; n < N; n++) { R[n] = 'A'; return R; } } //②最初のK文字がAと?1個だけで、かつK+1文字以降が全てAのとき //K文字のどこかはWだ //1箇所を除いてAのとき if (acount == K - 1 and qcount == 1 and ac) { for (int k = 0; k < K; k++) { if (R[k] == '?') { R[k] = 'W'; } } return R; } //決まらん return R; } for (int k = 0; k < K; k++) { R[k] = 'A'; } int acount = 0; for (int n = 0; n < N; n++) { if (R[n] == 'A') { acount++; } } if (acount == N - 1) { for (int n = 0; n < N; n++) { if (R[n] == '?') { R[n] = 'W'; } } } return R; } int main() { int T; cin >> T; vectorans(T); for (int t = 0; t < T; t++) { ans[t] = solve(); } for (int t = 0; t < T; t++) { cout << ans[t] << endl; } return 0; }