def solve(): S = [*input()] T = input() M = int(input()) N = len(S) if T == "Warong": S[:M] = ["A"] * M if "W" not in S[M:] and S[M:].count("?") == 1: S[S.index("?")] = "W" else: if "W" in S[M:] and all(s in ("A", "?") for s in S[:M]) and S[:M].count("?") == 1: S[S[:M].index("?")] = "W" elif all(s == "A" for s in S[:M]): S[M:] = ["A"] * (N - M) print(*S, sep="") if __name__ == "__main__": T = int(input()) for _ in range(T): solve()