P3167 [CQOI2014] Wildcard Matching

Description

Almost all operating systems' command-line interfaces (CLI) support wildcard matching for filenames to help users. The two most common wildcards are: an asterisk (```*```), which matches any sequence of characters of length 0 or more; and a question mark (```?```), which matches exactly one arbitrary character. You are to write a program that, given a list of filenames and a pattern string containing wildcards, determines which files can be matched.

Input Format

The first line is a string consisting of lowercase letters and the above wildcards. The second line contains an integer $n$, indicating the number of files. The next $n$ lines each contain a string consisting only of lowercase letters, representing the list of filenames.

Output Format

Output $n$ lines, each being ``YES`` or ``NO``, indicating whether the corresponding file can be matched by the pattern.

Explanation/Hint

For $100 \%$ of the testdata: - String length does not exceed 100000. - $1 \le n \le 100$. - The number of wildcards does not exceed 10. Translated by ChatGPT 5