#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } void solve() { string s, t; int k; cin >> s >> t >> k; int n = s.size(); if (t == "Warong") { rep(i, 0, k) s[i] = 'A'; int w = 0, ww = 0; rep(i, k, n) { if (s[i] == 'W') w++; if (s[i] == '?') ww++; } if (w == 0 && ww == 1) { rep(i, k, n) if (s[i] == '?') s[i] = 'W'; } cout << s << '\n'; return; } int q1 = 0, q2 = 0; rep(i, 0, k) if (s[i] == '?') q1++; rep(i, k, n) if (s[i] == '?') q2++; if (q1 == 0 && q2 > 0) { int na = 0; rep(i, 0, k) if (s[i] != 'A') na++; if (na == 0) { rep(i, k, n) if (s[i] == '?') s[i] = 'A'; } } else if (q1 > 0 && q2 == 0) { int cw = 0; rep(i, k, n) if (s[i] == 'W') cw++; if (cw > 0 && q1 == 1) { rep(i, 0, k) if (s[i] == '?') s[i] = 'W'; } } cout << s << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; cin >> t; while (t--) solve(); }