Under construction

Still being built. Things may change

Mysterious Device

Time limit2sMemory limit1024 MB

Summary
Given buttons that append fixed strings or delete a set number of characters, decide for each query string whether the screen can end up showing it.
Level

Medium7 of 10

Topics
String matching, Trie, Dynamic programming
Solved
No attempts yet

Problem

Dima has a device with n+mn + m buttons and a screen. The screen shows a string ss, which is initially empty.

Pressing button ii (1≤i≤n1 \le i \le n) appends the string wiw_i to the end of ss. Pressing button n+in + i (1≤i≤m1 \le i \le m) removes aia_i characters from the end of ss. If ss has fewer than aia_i characters, it becomes empty.

Dima has qq favorite strings tit_i. For each one, determine whether he can make ss equal to tit_i by pressing buttons some number of times, starting from the empty string ss.

Input

The first line contains two integers nn and mm (1≤n,m≤1000001 \le n, m \le 100000), the number of buttons of the first and second type.

The next nn lines contain non-empty strings wiw_i consisting of lowercase English letters. The total length of all strings wiw_i does not exceed 10610^6.

The next mm lines contain integers aia_i (1≤ai≤1061 \le a_i \le 10^6).

The next line contains an integer qq (1≤q≤1000001 \le q \le 100000), the number of Dima's favorite strings.

The next qq lines contain non-empty strings tit_i consisting of lowercase English letters. The total length of all strings tit_i does not exceed 10610^6.

Output

For each string tit_i, print Yes on its own line if ss can be made equal to tit_i, and No otherwise.

Examples1

  1. Example 1

    Input
    2 1
    bba
    abacaba
    2
    4
    b
    ababbab
    abacabba
    caba
    
    Expected output
    Yes
    Yes
    Yes
    No