TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

You may have ever heard about Caesar's code, which adds a constant value to each character then modulo every character by 26 as a "rotation" operation.


CiCaesar = Ci+k mod 26, for i=1,...,length(C)


Now, given a string S, you have to find out whether S was encoded from a segment of the following texts or not.
Of course, the encoding method should be Caesar's code.

Input Format

There are several cases in the input file.
The first line of the input file contains an integer T<=20 specifying the number of cases.

Every case starts with an integer N, followed by a string S with length 1<=N<=100000, composed by characters A-Z.
Then there's an integer 1<=M<=100, denoting the number of texts we want to examine.
The next M lines contain the description of M texts, expressed in the same format as S.

Output Format

For each text, output '1' if S is contained in an encoding of this text, otherwise output '0'.

Sample Input 1

1
3 ACB
2
5 ABDCE
6 FACDEB

Sample Output 1

1
0

Hints

Problem Source

Migrated from old NTUJ.

pP

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 2000 65536 200