This page is still under construction.

Parts of this page are still being built. What you see may change.

Substring Set Membership

Time limit1sMemory limit256 MB

Summary
You receive a set of patterns and query strings and print YES for each query containing a pattern as a contiguous substring, NO otherwise.
Level

Medium6 of 10

Topics
String matching, Trie
Solved
No attempts yet

Problem

The set SS has NN elements and every element is a string. Given QQ strings, decide for each one whether any of its substrings belongs to SS. Print YES if at least one substring is in SS, and NO if none of them is. A substring here means a contiguous stretch of the string.

For example, take SS to be {"www", "woo", "jun"}. The string "myungwoo" has the substring "woo", which is in SS, so its answer is YES. The string "hongjun" has the substring "jun", which is in SS, so its answer is YES. The string "dooho" has no substring in SS, so its answer is NO.

Input

The first line has the size NN of the set SS. (1≤N≤10001 \le N \le 1000)

Each of the next NN lines has one element of SS. No element is longer than 100100 characters.

The next line has QQ, the number of strings to decide. (1≤Q≤10001 \le Q \le 1000)

Each of the next QQ lines has one string to decide. No such string is longer than 1000010000 characters.

Every string in the input consists of lowercase letters only.

Output

Print QQ lines, one answer per input string, in the order the strings were given. Print YES if at least one substring of that string is in SS, and NO otherwise.

Examples1

  1. Example 1

    Input
    3
    www
    woo
    jun
    3
    myungwoo
    hongjun
    dooho
    
    Expected output
    YES
    YES
    NO