Aquarium

No attempts yetTime limit1sMemory limit128 MB

Problem

Kozik keeps an aquarium of African fish. Each fish has a mass and an age, and every day it must satisfy its hunger by eating one other, smaller fish; a fish that cannot eat dies at the end of that day.

Each day the fish act one at a time. The hungry fish with the greatest mass acts first; if several fish share the greatest mass, the oldest of them acts first. The acting fish devours the smallest fish currently in the aquarium; if several fish share the smallest mass, the youngest of them is eaten. When a fish devours another, its mass grows by half of the eaten fish's mass, and it is no longer hungry that day. If, when it is a fish's turn, no smaller fish is left to eat, that fish starves and dies at the end of the day.

Fish are compared first by mass, and for equal masses the younger fish counts as smaller. All ages are distinct, so this order is total, while masses may repeat. A fish can only devour a fish that is smaller than itself under this order.

For a chosen fish rr and a number of days xx, decide whether fish rr is still alive after xx days, where x=0x = 0 means right now.

Input

The first line contains an integer nn (1n1061 \le n \le 10^6), the number of fish.

Each of the next nn lines contains two integers mim_i and wiw_i (1mi,wi1091 \le m_i, w_i \le 10^9), the mass and the age of the ii-th fish.

The next line contains an integer zz (1z1061 \le z \le 10^6), the number of queries.

Each of the next zz lines contains two integers rkr_k and xkx_k (1rkn1 \le r_k \le n, 0xk1090 \le x_k \le 10^9), asking whether fish rkr_k is still alive after xkx_k days.

Output

For each query, print TAK if fish rkr_k is still alive after xkx_k days, or NIE otherwise. Here TAK means yes and NIE means no. Print one answer per line, in the order of the queries.