CF2000C.Numeric String Template

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Numeric String Template

Kristina has an array aa, called a template, consisting of nn integers. She also has mm strings, each consisting only of lowercase Latin letters. The strings are numbered from 11 to mm. She wants to check which strings match the template.

A string ss is considered to match the template if all of the following conditions are simultaneously satisfied:

  • The length of the string ss is equal to the number of elements in the array aa.
  • The same numbers from aa correspond to the same symbols from ss. So, if ai=aja_i = a_j, then si=sjs_i = s_j for (1i,jn1 \le i, j \le n).
  • The same symbols from ss correspond to the same numbers from aa. So, if si=sjs_i = s_j, then ai=aja_i = a_j for (1i,jn1 \le i, j \le n).

In other words, there must be a one-to-one correspondence between the characters of the string and the elements of the array.

For example, if aa = [3,5,2,1,33, 5, 2, 1, 3], then the string "abfda" matches the template, while the string "afbfa" does not, since the character "f" corresponds to both numbers 11 and 55.

Input

The first line of input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The following descriptions are for the test cases.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of elements in the array aa.

The second line of each test case contains exactly nn integers aia_i (109ai109-10^9 \le a_i \le 10^9) — the elements of the array aa.

The third line of each test case contains a single integer mm (1m21051 \le m \le 2 \cdot 10^5) — the number of strings to check for template matching.

Following are mm strings, each containing a non-empty string sjs_j (1sj21051 \le |s_j| \le 2 \cdot 10^5), consisting of lowercase Latin letters.

It is guaranteed that the sum of nn across all test cases does not exceed 21052 \cdot 10^5, and that the sum of the lengths of all strings does not exceed 21052 \cdot 10^5.

Output

For each test case, output mm lines. On the ii-th line (1im1 \le i \le m) output:

  • "YES", if the string with index ii matches the template;
  • "NO" otherwise.

You may output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

Note

The first test case is explained in the problem statement.

Samples

3
5
3 5 2 1 3
2
abfda
afbfa
2
1 2
3
ab
abc
aa
4
5 -3 5 -3
4
aaaa
bcbc
aba
cbcb
YES
NO
YES
NO
NO
NO
YES
NO
YES

在线编程 IDE

建议全屏模式获得最佳体验