Intelligence Test
Time limit3sMemory limit512 MB
Given a fixed sequence and several queries, decide for each query sequence whether it is a subsequence of the fixed sequence.
- Level
Easy3 of 10
- Topics
- Array, Two pointers, Greedy
- Solved
- No attempts yet
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 ().
The second line holds integers (), separated by single spaces, that form the initial sequence.
The third line holds one integer .
The following 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 (), and the second holds integers (), separated by single spaces.
The total length of the given target sequences does not exceed .
Output
Print lines. The -th line should hold the word TAK (Polish for yes) if the -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.