#P1248. Special Week With Passwords

Special Week With Passwords

题目描述

Password, password and also the password! In this Internet world, one can not live without a password. We can use our account to pay something or chat with others or something else.

Also, Special Week has some passwords, but unfortunately, she has forgotten some of them.

In order to remember the passwords, she also has some principles in the password generation like most people, who always use their birthday as the password, which is about the prefixes.

A prefix of one string is like for example:

aabbaabb aa is the prefix, aaaa also is the prefix, aabaab is also the prefix, and aabbaabb is also the prefix.

bust abab is not the prefix as the prefix need to be consecutive.

So, this time Special Week just has reminded some of her passwords but has also forgotten some of her passwords.

The algorithm of her password generation is below:

  1. Generate some random strings like abcdabcd ddsadkjddsadkj.
  2. Concatenate the prefixes of all the random strings with random length and the original order. For example, we can get abddsaabddsa just Concatenate the prefix of abcdabcd and ddsadkjddsadkj with the prefix abab and ddsaddsa. Please notice that we can't get ddsaabddsaab because we need to concatenate them with the original order.
  3. Every string must contribute its prefix.

Now Special Week has remembered some of her passwords, but she doesn't know whether it is right. Please help her check them.

输入格式

The first line contains one positive integer n(1lenle5)n (1\\le n\\le 5) indicating the number of the random strings.

Then followed nn lines, each line contains one string of length at most 55.

Then followed one positive integer m(1lemle1000)m (1\\le m\\le 1000) indicating the number of the queries.

Then followed mm lines, each line contains one password of length at most 25 which might be right.

All strings only consist of lowercase English letters.

输出格式

For each query, if the password is right Then print YES, otherwise print NO

样例

3 
abc 
ab 
abaad 
4 
aaa 
aaad 
ababa 
aabab 

YES 
NO 
YES 
YES