Monotone Walkway

No attempts yetTime limit5sMemory limit256 MB

Problem

There is a walkway that is famous as a hiking course. Its entrance is the westmost point of the walkway. The walkway is a simple path made only of horizontal runs and vertical runs, so at every corner it turns 90 degrees, either left or right. Walking from the entrance toward the exit, you never move from east to west, which means you reach the exit without the x coordinate of your position ever getting smaller. That is why the walkway is called a monotone walkway. Figure 1 shows an example of a monotone walkway.

Figure 1. An example of a monotone walkway

There are nn cafes along the walkway. The entrance, the exit and every corner all have a cafe. Kim, who manages the course, has the coordinates of every cafe on the walkway. The entrance is always at the origin (0,0)(0, 0). Kim wants to number the cafes from 1 to nn. The cafe at the entrance gets number 1, and the rest get their numbers in the order you meet them while following the walkway. If you meet cafe A before cafe B on the way from the entrance to the exit, then A gets a smaller number than B. So on the walkway of figure 1, the cafe at (3,1)(3, 1) is number 5, the cafe at (9,0)(9, 0) is number 14, and the cafe at the exit is number 17. Kim wants to finish this job from the coordinates alone, without walking the course. Help Kim and write a program that numbers the cafes.

Input

Input is given on standard input. The first line holds the number of test data TT (1T101 \le T \le 10). The first line of each test datum holds an integer nn (2n100,0002 \le n \le 100{,}000), the number of cafes. Each of the next nn lines holds two integers xx and yy, the coordinates of one cafe (0x100,0000 \le x \le 100{,}000, 100,000y100,000-100{,}000 \le y \le 100{,}000). The coordinates come in arbitrary order, unrelated to the order of the walk. The entrance is always at (0,0)(0, 0), and no two cafes share the same coordinates. The last line holds an integer mm (1m101 \le m \le 10) and mm integers. Each of the mm integers is a cafe number between 1 and nn.

Output

Print to standard output. For each test datum, print the answer for the mm given cafe numbers in the given order, one per line. The answer for the number kk is the pair of integers xx and yy, the coordinates of the cafe numbered kk, separated by one space.