This page is still under construction.

Parts of this page are still being built. What you see may change.

Bytean Road Race

Time limit3sMemory limit64 MB

Summary
Given a planar south/east DAG from node 1 to node n, answer queries asking whether some monotone path passes through both given crossings.
Level

Hard8 of 10

Topics
Graph, DFS, Dynamic programming, Sorting
Solved
No attempts yet

Problem

The Bytean Road Race will be held tomorrow in the center of Bytetown. The city's streets form a regular grid: every street runs either south-to-north or west-to-east. Runners may use only certain marked parts of these streets.

Byteasar has to place the sponsors' banners at some of the crossings, so he studies the race map. The map shows the street segments the runners are allowed to use. There are nn crossings and mm horizontal or vertical road segments. Each segment begins and ends at a crossing and contains no crossing in its interior; two segments may meet only at a crossing.

The crossings are numbered from 11 to nn. The race starts at crossing 11 and finishes at crossing nn. Each runner chooses their own route, but may move only south and east, and only along the marked segments. The marked segments are arranged so that, obeying these rules, the finish can be reached from every crossing and every crossing can be reached from the start.

Byteasar wants no runner to see the same sponsor's banner twice. To arrange this he needs to know, for certain pairs of crossings, whether some runner's route can pass through both crossings of the pair. Help him answer these questions.

Input

The first line contains three integers nn, mm, and kk (2≤n≤100 0002 \le n \le 100\,000, 1≤m≤200 0001 \le m \le 200\,000, 1≤k≤300 0001 \le k \le 300\,000): the number of crossings, the number of marked segments, and the number of crossing pairs to check.

The next nn lines describe the crossings. The ii-th of them contains two integers xix_i and yiy_i (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9), the coordinates of crossing ii. The OXOX axis points east and the OYOY axis points north. Moreover x1≤xnx_1 \le x_n and y1≥yny_1 \ge y_n, and no two crossings lie at the same point.

Each of the next mm lines contains two integers aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i): the two crossings joined by one segment. Every segment is horizontal or vertical, and two segments meet only at a shared endpoint.

Each of the next kk lines contains two integers pip_i and qiq_i (1≤pi,qi≤n1 \le p_i, q_i \le n, pi≠qip_i \ne q_i): a pair of crossings to check.

Output

Output kk lines. The ii-th line should contain TAK if some runner's route can pass through both crossings pip_i and qiq_i (in either order), and NIE otherwise. (TAK means yes and NIE means no.)

Hint

Examples3

  1. Example 1

    Input
    9 10 4
    1 6
    2 6
    4 4
    1 4
    3 4
    4 6
    6 4
    3 1
    6 1
    1 2
    4 1
    2 6
    3 6
    5 4
    5 3
    5 8
    3 7
    7 9
    9 8
    4 8
    2 5
    8 7
    7 6
    
    Expected output
    TAK
    NIE
    NIE
    TAK
    
  2. Example 2

    Input
    2 1 1
    0 0
    1 0
    1 2
    1 2
    
    Expected output
    TAK
    
  3. Example 3

    Input
    4 4 5
    0 1
    1 1
    0 0
    1 0
    1 2
    1 3
    2 4
    3 4
    2 3
    3 2
    1 4
    2 4
    1 2
    
    Expected output
    NIE
    NIE
    TAK
    TAK
    TAK