import sys def debug(*args): print(*args, file=sys.stderr) T = int(input()) for _ in range(T): R = input() S = input() K = int(input()) if S == "NotWarong": print(R) continue ret = "A" * K s = R[K:] if s.count("W") == 0: s.replace("?", "W", 1) ret += s print(ret)