Intelligence Test

No attempts yetTime limit3sMemory limit512 MB

Problem

One of the tasks in the Byteotian Intelligence Test (BIT) is to cross out numbers from an initial sequence so that a given target sequence is left. Byteasar longs to become the IQ Master of Byteotia, but he is not good at this kind of task. Since practice makes perfect, he intends to practise a great deal, and he asks you to write a program that speeds up his training by checking his answers quickly.

In other words, given the initial sequence and a target sequence, decide whether the target can be obtained by removing some (not necessarily contiguous) numbers from the initial sequence. The order of the numbers left after crossing out is preserved.

Input

The first line contains one integer mm (1m1061 \le m \le 10^6).

The second line holds mm integers a1,a2,,ama_1, a_2, \ldots, a_m (1ai1061 \le a_i \le 10^6), separated by single spaces, that form the initial sequence.

The third line holds one integer nn.

The following 2n2n lines describe the sequences to be obtained by crossing out numbers from the initial sequence. Each target sequence is given on two lines: the first holds an integer mim_i (1mi1061 \le m_i \le 10^6), and the second holds mim_i integers bi,1,bi,2,,bi,mib_{i,1}, b_{i,2}, \ldots, b_{i,m_i} (1bi,j1061 \le b_{i,j} \le 10^6), separated by single spaces.

The total length of the nn given target sequences does not exceed 10610^6.

Output

Print nn lines. The ii-th line should hold the word TAK (Polish for yes) if the ii-th target sequence can be obtained by crossing out (removing) some, not necessarily contiguous, numbers from the initial sequence, or NIE (Polish for no) otherwise. The order of the numbers left after crossing out matters. Print only the words, without quotation marks.