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.
The first line contains one integer m (1≤m≤106).
The second line holds m integers a1,a2,…,am (1≤ai≤106), separated by single spaces, that form the initial sequence.
The third line holds one integer n.
The following 2n 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 mi (1≤mi≤106), and the second holds mi integers bi,1,bi,2,…,bi,mi (1≤bi,j≤106), separated by single spaces.
The total length of the n given target sequences does not exceed 106.
Print n lines. The i-th line should hold the word TAK (Polish for yes) if the i-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.