This page is still under construction.

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

Hi! I'm Luffy! I'm the man who will become the Pirate King!

Time limit1sMemory limit128 MB

Summary
Given island coordinates and left-of constraints per map, list every island that can be the viewpoint so all listed islands lie in a forward half-plane and constraints hold.
Level

Hard8 of 10

Topics
Geometry, Sorting, Binary search
Solved
No attempts yet

Problem

Hi! I'm Monkey D. Luffy, the man who's going to become the Pirate King! A few days ago we got our hands on a treasure map that marks the island where the legendary treasure, the One Piece, is hidden. Now we have to read this map and work out where the treasure island is.

The coast where the treasure island lies is dotted with a huge number of tiny islands, so searching them one by one would take far too long. This treasure map is unusual, though: it is not a bird's-eye view from above. Instead it records only which islands are seen, and in what order, when you stand on the peak of the treasure island and look out toward the sea in one direction.

Whoever drew it stood on the peak, faced a single direction with a 180180-degree forward field of view, and lined up every visible island from left to right. So an island drawn further to the left on the map really does appear further to the left from that vantage point. The artist was terrible, so the distances between islands do not match reality at all, and any island hidden by the thick fog was simply not drawn. Even so, the left-to-right order of the islands that were in view is exact, and every island carries a mark identifying which island it is.

Along with several such treasure maps, we also have a bird's-eye chart giving the exact position of every island on that coast. Each treasure map is given as a handful of facts of the form "island A appeared to the left of island B".

If we pick one island, stand on it, and face a suitable direction so that all islands appearing on that map fall within the 180180-degree forward field of view and every "island A is left of island B" fact holds, then that island is a possible treasure island. For each treasure map, find every island that could be the treasure island!

Input

The first line contains the number of test cases TT. Each test case has the following format.

  • The first line contains the number of islands nn. (1≤n≤1250001 \le n \le 125000)
  • Each of the next nn lines contains two integers xix_i and yiy_i, the coordinates of island ii. (0<xi,yi<2290 < x_i, y_i < 2^{29})
  • The next line contains the number of treasure maps (queries) kk for this coast. Each treasure map is given as follows.
    • The first line contains the number of facts mm. (0≤m≤100000 \le m \le 10000)
    • Each of the next mm lines contains two integers ll and rr (1≤l,r≤n1 \le l, r \le n, l≠rl \ne r), meaning that on that map island ll was drawn to the left of island rr.

Within one coast, no two islands share the same xx-coordinate, no two islands share the same yy-coordinate, and no three islands are collinear.

Output

For each treasure map, print the numbers of the islands that could be the treasure island, one per line in ascending order. Then print a single integer 00 on its own line to end the output for that map. If there is no possible treasure island, print only 00.

Hint

The sample input describes the same situation as the map in the statement. From the given facts, the islands that could be the treasure island are islands 66, 77, and 88 (Rummet, Alet, Schnaphpsum).

Examples1

  1. Example 1

    Input
    1
    9
    28 34
    32 30
    12 29
    27 22
    42 23
    18 18
    5 14
    26 12
    34 5
    1
    4
    1 2
    1 9
    2 9
    4 5
    
    Expected output
    6
    7
    8
    0