Hide

Problem A
Deterministic Finite Automata - Read

Languages en is

You are given a deterministic finite automaton and a list of strings. For each string given, you should determine whether the automaton accepts or rejects the string.

Input

The first line of input contains four positive integers $n$, $c$, $s$, and $f$, where $n$ is the number of states, $c$ is the size of the alphabet, $s$ is the initial state, and $f$ is the number of final states. The second line consists of a string $\Sigma = \Sigma _1\Sigma _2\dots \Sigma _c$ of $c$ distinct symbols, each of which is a lowercase english character. The third line consists of $f$ distinct positive integers, the set of final states. Then $n$ lines follow, each with $c$ positive integers, describing the symbol table. The $j$-th integer on the $i$-th of those lines represents the state transitioned to from state $i$ upon reading $\Sigma _j$.

Each state is an integer between $1$ and $n$. It is guaranteed that $n \cdot c \leq 100\, 022$, $1 \leq s \leq n$, and $0 \leq f \leq n$.

After that a line with the integer $m$ follows, the number of strings to check, where $1 \leq m \leq 100\, 000$. Then $m$ lines follow, each with a string to check. Each string is between $0$ and $100\, 000$ characters in length and the total length of all strings combined is at most $100\, 000$. Each string will only consist of characters from the alphabet $\Sigma $.

Output

For each string to check, output a line containing either accept or reject, depending on whether the string was accepted or rejected.

Sample Input 1 Sample Output 1
3 2 1 1
ab
1
1 2
1 3
3 3
6

a
aa
ab
abba
aabaababa
accept
accept
accept
reject
reject
accept
Sample Input 2 Sample Output 2
1 4 1 0
acgt

1 1 1 1
3

agaga
gattaca
reject
reject
reject