import sys input = sys.stdin.readline from collections import deque from bisect import bisect_left, bisect_right import itertools #from math import * for t in range(1, int(input())+1): ans = "NO" arr = list(map(int, input().split())) c = int(input()) st = set() for i in range(c): r = tuple([arr[ord(q)-65] for q in input().strip()]) if r in st: ans = "YES" st.add(r) print("Case #{}: {}".format(t, ans))