tests = int(input()) for case in range(1, tests+1): mapping = input().split() n = int(input()) words = [input() for _ in range(n)] mapped_words = [ "".join([mapping[ord(c)-ord('A')] for c in word]) for word in words ] word_set = set() for mapped_word in mapped_words: word_set.add(mapped_word) if len(word_set) == n: print(f"Case #{case}: NO") else: print(f"Case #{case}: YES")