T = int(input()) for t in range(T): # Read input mapping = input().split() N = int(input()) words = [input().strip() for i in range(N)] # Encode words using the mapping encoded = {} for word in words: code = ''.join(mapping[ord(c) - ord('A')] for c in word) if code in encoded: print(f"Case #{t+1}: YES") break encoded[code] = word else: print(f"Case #{t+1}: NO")