Under construction

Still being built. Things may change

Injured Shoulder

Interview

Time limit5sMemory limit1024 MB

Summary
Given a dictionary and typed words, print 1 if a word is in the dictionary, 2 if it is two dictionary words joined without a space, and 0 otherwise.
Level

Easy3 of 10

Topics
String, Hash map
Solved
No attempts yet

Problem

Dr. Orooji injured his right shoulder a few months ago and could type with only one hand for a while. For some reason, Dr. O often missed the space character (blank), so two words ended up next to each other without a space, and the spell-checker flagged them.

Given the words in a dictionary and a word Dr. O has typed, determine the status of the typed word.

Input

The first line contains an integer nn (2≤n≤202 \le n \le 20), the number of words in the dictionary. Each of the next nn lines contains one dictionary word. Each word starts in column 1, contains at least one and at most 20 lowercase letters, and no other characters. The dictionary words are unique.

The next line contains an integer mm (1≤m≤1001 \le m \le 100), the number of words Dr. O has typed. Each of the next mm lines contains one typed word. Each typed word starts in column 1, contains at least one and at most 40 lowercase letters, and no other characters.

Output

For each typed word, print one line:

  • 1: if the typed word is in the dictionary.
  • 2: if the typed word is a concatenation of two dictionary words, meaning Dr. O left out the space character.
  • 0: otherwise.

If a typed word is in the dictionary and is also a concatenation of two dictionary words, the output is 1.

Examples1

  1. Example 1

    Input
    7
    this
    is
    a
    test
    th
    the
    e
    12
    is
    test
    isthis
    the
    th
    ee
    eee
    thee
    best
    istestis
    e
    ea
    
    Expected output
    1
    1
    2
    1
    1
    2
    0
    2
    0
    0
    1
    2