Олимпиадный тренинг

Задача 23376. British scientists (B, A', A)


Задача

Темы:
According to research by British scientists, people are able to perceive words in a text if the first and last letters are left in place in each word, and the rest are randomly mixed; for example, the word "program" can be read even if written as
"pgrrommaa" or "pmorgamra".
You are given a dictionary with a few words, as well as some text. For each word in the text, determine if it can be read as one of the words in the dictionary, following the rules described above.
 
Input data format
The first line contains a single integer n (1 <=  n <= 105)   is the number of words in the dictionary.
The next n lines contain words from the dictionary, one per line. It is guaranteed that all words in the dictionary are distinct.
The next line contains one integer m (1 <= m <= 105) - the number of words in the text.
The next m lines contain words from the text, one per line.
Each word consists only of lowercase letters of the Latin alphabet; there are no spaces or other separators in any input line. The total length of all words does not exceed 105.
 
Output format
For each word from the text print "YES" if it can be read as one of the dictionary words, and "NO" otherwise. Answers for words from the text should be displayed in the same order, in
which words are listed in the input; should output one response per line.


Enter Output
4
bird
sun
lksh
summer
4
Brid
snu
sommer
sis
YES
NO
NO
NO