T = int(input()) for case in range(1,T+1): Ds = list(map(int, input().strip().split())) dct = {c : d for c,d in zip("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Ds)} N = int(input()) ans = "NO" words = [] for _ in range(N): S = input().strip() w = [] for c in S: w.append(dct[c]) words.append(tuple(w)) ans = "YES" if len(words) != len(set(words)) else "NO" print(f"Case #{case}: {ans}")