Codeforces Round 425 (Div. 2)
B
Petya and Exam
Codeforces
1600
原题
← AC →
翻译中…

It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..

翻译中…

There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.

翻译中…

Also, $*n*$ query strings are given, it is required to determine for each of them if the pattern matches it or not.

翻译中…

Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.

翻译中…

A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.

翻译中…

The good letters are given to Petya. All the others are bad.

翻译中…

Input

翻译中…

The first line contains a string with length from $1$ to $26$ consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.

翻译中…

The second line contains the pattern — a string $*s*$ of lowercase English letters, characters "?" and "*" ($1 ≤ |*s*| ≤ 10^{5}$). It is guaranteed that character "*" occurs in $*s*$ no more than once.

翻译中…

The third line contains integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$) — the number of query strings.

翻译中…

$*n*$ lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string.

翻译中…

It is guaranteed that the total length of all query strings is not greater than $10^{5}$.

翻译中…

Output

翻译中…

Print $*n*$ lines: in the $*i*$-th of them print "YES" if the pattern matches the $*i*$-th query string, and "NO" otherwise.

翻译中…

You can choose the case (lower or upper) for each letter arbitrary.

翻译中…

Note

翻译中…

In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.

翻译中…

Explanation of the second example.

翻译中…
  • The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good.
  • The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide.
  • The third query: "NO", because characters "?" can't be replaced with bad letters.
  • The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".
翻译中…

样例

Input #1
ab
a?a
2
aaa
aab
Output #1
YES
NO
InputCopy OutputCopy
Input #2
abc
a?a?a*
4
abacaba
abaca
apapa
aaaaax
Output #2
NO
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
832B
时间限制
2 s
内存限制
256 MB
标签
模拟
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。