using System.Text; using System.IO; using System.Collections.Generic; using System.Linq; using System.Diagnostics; namespace ConsoleApp1 { public class A { void SolveTest(TextReader reader, TextWriter writer, int testNumber) { string line1 = reader.ReadLine().Trim(); var l = new Dictionary(); var array = line1.Split(' ').Select(int.Parse).ToArray(); for (char c = 'A'; c <= 'Z'; ++c) { l.Add(c, array[(int) (c - 'A')]); } int wC = int.Parse(reader.ReadLine()); HashSet s = new HashSet(); bool ans = false; HashSet processed = new HashSet(); for (int x = 0; x < wC; ++x) { string www = reader.ReadLine(); if (processed.Contains(www)) continue; StringBuilder sb = new StringBuilder(); for (int t = 0; t < www.Length; ++t) { sb.Append(l[www[t]]); } string code = sb.ToString(); if (s.Contains(code)) { ans = true; } processed.Add(www); s.Add(code); } string a = ans ? "YES" : "NO"; writer.WriteLine($"Case #{testNumber}: {a}"); } void SolveAll(TextReader reader, TextWriter writer) { int testCount = int.Parse(reader.ReadLine()); for (int i = 0; i < testCount; ++i) { SolveTest(reader, writer, i + 1); } } private static readonly string inputFileName = "input.txt"; private static readonly string outputFileName = "output.txt"; public static void Main(string[] args) { A a = new A(); if (args.Contains("file")) { using (var reader = new StreamReader(new FileStream(inputFileName, FileMode.Open))) { using (var writer = new StreamWriter(outputFileName)) { a.SolveAll(reader, writer); } } } else { a.SolveAll(System.Console.In, System.Console.Out); } } } }