本站作为LDUOnlineJudge的测试版本进行演示,官方网站请访问http://icpc.ldu.edu.cn
[Hidden]

1286. B. Phoneme Palindromes


Description

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.


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

Input

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.

Output

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.

Samples

Input Copy
2
1
c k
6
a
cac
ck
cab
kaak
ckckkcck
2
a z
x s
5
abbbz
asxz
cx
sxxabzxss
ks
Output
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

Source

UCF2016
Problem Information

Time Limit: 1000MS (C/C++,Others×2)
Memory Limit: 128MB (C/C++,Others×2)
Special Judge: No
AC/Submit: 1 / 1
Tags:
Contests involved

1032. UCF 2016
My history solutions

You didn't submit any solution!
Submit your solution

Login Register