Cards

No attempts yetTime limit3sMemory limit256 MB

Problem

There are nn cards laid out in a row on a table. Each card has one integer written on its obverse and one on its reverse, and every card starts with its obverse facing up.

Byteasar the great illusionist wants to perform his signature trick, Binary Search Card Manipulation, several times. The trick works only when the numbers facing up are non-decreasing from left to right, so Byteasar may turn over some cards to expose the numbers on their reverse sides.

The trick also needs a volunteer from the audience. Some volunteers are planted by Byteasar's competitors, and each of them swaps two cards on the table with one quick move of a hand the moment he steps on stage. After a swap Byteasar may again turn over any cards he wants, yet he still might not be able to perform the trick.

Write a program that decides, after every swap, whether Byteasar can perform the trick.

Input

The first line contains the number of cards nn (2n2000002 \le n \le 200000). Each of the next nn lines describes one card, in the order the cards lie on the table. The ii-th of these lines contains two integers xix_i and yiy_i (0xi,yi1070 \le x_i, y_i \le 10^7) separated by one space. xix_i is written on the obverse of the ii-th card and yiy_i on its reverse. The starting arrangement is not guaranteed to allow the trick.

The next line contains the number of swaps mm (1m10000001 \le m \le 1000000). Each of the next mm lines describes one swap, in the order the swaps happen. The jj-th of these lines contains two integers aja_j and bjb_j (1aj,bjn1 \le a_j, b_j \le n) separated by one space, meaning that the jj-th volunteer exchanges the cards at positions aja_j and bjb_j. Every swap acts on the arrangement left by all earlier swaps. If aja_j equals bjb_j, the arrangement does not change.

Output

Print mm lines. Line jj contains TAK if Byteasar can turn cards over so that the visible numbers are non-decreasing after the jj-th swap, and NIE otherwise. The set of turned cards may be chosen anew after each swap. TAK and NIE are Polish for yes and no.