Permutation

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a sequence of positive integers a1,a2,,ana_1, a_2, \ldots, a_n. You want to place the numbers 11 through nn, each exactly once, into positions 11 through nn, so that the number placed at position ii never exceeds aia_i. In other words, decide whether a permutation pp of 1,,n1, \ldots, n exists such that piaip_i \le a_i for every 1in1 \le i \le n.

Write a program that reports, for the initial sequence and after each single edit to the sequence, whether such a permutation can be formed.

Input

The first line contains the length of the sequence nn (1n200,0001 \le n \le 200{,}000). The second line contains a1,a2,,ana_1, a_2, \ldots, a_n separated by spaces. The third line contains the number of edits mm (0m500,0000 \le m \le 500{,}000). Each of the next mm lines describes one edit as two integers jij_i and wiw_i (1ji,win1 \le j_i, w_i \le n), meaning the jij_i-th element is changed to wiw_i. Edits are applied cumulatively: the ii-th edit is made to the sequence that already includes the previous i1i-1 edits.

Output

Print m+1m+1 lines. On each line print TAK if a permutation satisfying the condition can be formed, or NIE if it cannot.

The first line is the answer for the initial sequence, and the next mm lines are the answers immediately after the 11st through mmth edits are applied.

Hint

In the sample, the initial sequence admits the permutation 2,4,3,1,52, 4, 3, 1, 5. After the first edit the sequence becomes 3,4,3,2,43, 4, 3, 2, 4, for which no permutation exists. After the second edit it becomes 5,4,3,2,45, 4, 3, 2, 4, for which the permutation 5,1,3,2,45, 1, 3, 2, 4 works.