#C119. Anagram Cipher

    ID: 41266 Type: Default 1000ms 256MiB

Anagram Cipher

Anagram Cipher

In this problem, you are given a list of dictionary words and a list of test words. For each test word, determine whether any permutation of the test word exists in the dictionary. In other words, for a test word (W), if there exists any word in the dictionary whose sorted characters match the sorted characters of (W), then output “YES”; otherwise, output “NO”.

The input first includes an integer (N) denoting the number of dictionary words, followed by (N) lines, each containing a word. Then, an integer (T) is given representing the number of test words, followed by (T) lines with each test word. For each test word, output a line with either “YES” or “NO”.

inputFormat

The first line contains an integer (N) ( (1 \leq N \leq 10^5)) which is the number of dictionary words. The next (N) lines each contain a dictionary word. The following line contains an integer (T) ( (1 \leq T \leq 10^5)) representing the number of test words. The next (T) lines each contain a test word.

outputFormat

For each test word, print a single line with "YES" if any permutation of the test word exists in the dictionary; otherwise, print "NO".## sample

5
listen
enlist
google
silent
tinsel
3
inlets
etslin
glgoo
YES

YES NO

</p>