#P12422. Subsequence Division

    ID: 14526 Type: Default 1000ms 256MiB

Subsequence Division

Subsequence Division

We define (S\mid T) as follows: Let (k=\lfloor|T|/|S|\rfloor). Then, (S) repeated (k) times (i.e., (\underbrace{S S \cdots S}_{k})) must appear as a subsequence in (T). For example, if (S=\textsf{ab}) and (T=\textsf{abcab}), then (S\mid T) holds since the subsequence can be highlighted as abcab.

For (t) test cases, you are given a string (S) and a positive integer (q). For each of the (q) queries, a string (T_i) is provided. You need to check whether (T_i\mid S) holds. In other words, let (k=\lfloor|S|/|T_i|\rfloor) (if (k=0), consider it as invalid), and check if (T_i) repeated (k) times is a subsequence of (S). Output Yes if it is, and No otherwise.

inputFormat

The first line contains an integer (t), the number of test cases. For each test case:
1. The first line contains the string (S).
2. The second line contains an integer (q), the number of queries.
3. Each of the next (q) lines contains a query string (T_i).

outputFormat

For each query, output Yes if (T_i\mid S) holds; otherwise, output No. Each answer should be printed on its own line.

sample

3
abcab
2
ab
ac
aaaaa
2
aa
aaa
ababa
2
aba
b
Yes

No Yes Yes Yes No

</p>