QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#569. Intelligence Test

الإحصائيات

One of the tasks in the Byteotian Intelligence Test (BIT) is to cross out numbers from an initial sequence in such a way that leaves as a result certain given sequences. Byteasar longs to become the IQ Master of Byteotia, but he is no good in this kind of tasks. But since practice makes perfect, he intends to practise a lot. So much in fact that he asks you to write a program that will facilitate the training by verifying his answers quickly.

Input

The first line of the standard input contains one integer $m$ ($1 ≤ m ≤ 1\,000\,000$). The second line holds $m$ integers $a_1,a_2,…,a_m$ ($1 ≤ a_i ≤ 1\,000\,000$ for $1 ≤ i ≤ m$), separated by single spaces, that constitute the initial sequence of the test. The third line of the input holds one integer $n$. The following $2n$ lines describe the sequences to be obtained by crossing out numbers from the initial sequence. Each sequence's description takes two successive lines. The first of these two lines contains $a_n$ integer $m_i$ ($1 ≤ m_i ≤ 1\,000\,000$). The second contains an $m_i$-element long sequence of integers $b_{i,1},b_{i,2},…,b_{i,m_i}$ ($1 ≤ b_{i,j} ≤ 1\,000\,000$ for $1 ≤ j ≤ m_i$) separated by single spaces. You may assume that the total length on given $n$ sequences does not exceed $1\,000\,000$.

Output

Your program should print out $n$ lines to the standard output. The $i$-th line (for $1 ≤ i ≤ n$) should hold one word, "TAK" (yes in Polish) if the $i$-th input sequence can be obtained by crossing out (i.e., removing) some, not necessarily contiguous, numbers from the initial sequence, or "NIE" (no in Polish) otherwise. Mind you, only the words should be printed, no quotation marks. Of course, the order of the numbers left after crossing out is important, as can be seen in the example.

Example

Input

7
1 5 4 5 7 8 6
4
5
1 5 5 8 6
3
2 2 2
3
5 7 8
4
1 5 7 4

Output

TAK
NIE
TAK
NIE
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.