def solve(): R = input().strip() wrong = input().strip() == "Warong" K = int(input()) if wrong: # AAAA...AAA latter = R[K:] q_ct = latter.count("?") w_ct = latter.count("W") if q_ct == 1 and w_ct == 0: latter.replace("?", "W") print(R[:K].replace("?", "A") + latter) else: former = R[:K] latter = R[K:] if former.count("A") != K: print(R) else: # 全てA print("A" * len(R)) for _ in range(int(input())): solve()