시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB17012411372.436%

문제

A palindrome is a string that reads the same forward and backward, e.g., madam and abba. Since some letters sound the same (e.g., c and k), we define a phoneme palindrome as a string that sounds the same forward and backward, e.g., cak and ckckbbkcck.

Given the letters that sound the same and a string, you are to determine if the string is a phoneme palindrome.

입력

The first input line contains a positive integer, n, indicating the number of test cases to process. Each test case starts with an integer, p (1 ≤ p ≤ 13), indicating the count for pairs of letters that sound the same. Each of the following p input lines provides two distinct lowercase letters (starting in column 1 and separated by a space) that sound the same. Assume that no letter appears in more than one pair. The next input line for a test case contains an integer, q (1 ≤ q ≤ 100), indicating the number of strings to test for phoneme palindrome. Each of the following q input lines provides a string (starting in column 1 and lowercase letters only) of length 1 to 50, inclusive.

출력

For each test case, print the header “Test case #n:”, where n indicates the case number starting with 1. Then print each string for that test case followed by a space, followed by a message (YES or NO) indicating whether or not the string is a phoneme palindrome. Leave a blank line after the output for each test case.

예제 입력 1

2
1
c k
6
a
cac
ck
cab
kaak
ckckkcck
2
a z
x s
5
abbbz
asxz
cx
sxxabzxss
ks

예제 출력 1

Test case #1:
a YES
cac YES
ck YES
cab NO
kaak YES
ckckkcck YES

Test case #2:
abbbz YES
asxz YES
cx NO
sxxabzxss YES
ks NO