from typing import Dict, Any class SolutionBase: # internal code for @staticmethod def read_int(): return int(input()) @staticmethod def read_ints(): return [int(i) for i in input().split()] @staticmethod def read_line(): return input().strip() # implementation in subclass def load_data(self) -> Dict[str, Any]: raise NotImplementedError def solve(self, **kwargs): raise NotImplementedError def format_answer(self, answer) -> str: raise NotImplementedError def main(self): t = self.read_int() for i in range(1, t+1): answer = self.format_answer( self.solve( **self.load_data() ) ) print(f"Case #{i}: {answer}") class MySolution(SolutionBase): def load_data(self) -> Dict[str, Any]: alphabet_map = self.read_ints() n = self.read_int() encode_list = [ self.read_line() for i in range(n) ] return { 'alphabet_map': alphabet_map, 'encode_list': encode_list } def encode_word(self, alphabet_map, word): encoded_list = [ str(alphabet_map[ord(char) - ord('A')]) for char in word ] return "".join(encoded_list) def solve(self, alphabet_map, encode_list) -> bool: encoded_set = set() for word in encode_list: encoded = self.encode_word(alphabet_map, word) if encoded in encoded_set: return True encoded_set.add(encoded) return False def format_answer(self, answer: bool) -> str: if answer: return "YES" else: return "NO" if __name__ == "__main__": MySolution().main()