Problem D

Galactic Transmission

 

After the great war of Doom galactic empire lost its control over the periphery planets. They tried to hold on the planets near the center of the galaxy. Most of the battleships and communication means were lost. All they could do to control these planets was issuing commands to the planetary governments through two central broadcasting planets.


Due to disturbance in galactic magnetic fields, the effective broadcasting radius that these two planets transmit varies between times. During each transmission physicists calculate how far they can transmit and kept a log of these transmission records.

For each transmission record the emperor wants to know how many planets received that particular transmission.

 

Input

 

The first line contains n (3 <= n <= 500,000), number of planets in the center of the galaxy. After that n lines will follow each containing three integers x, y, z (-500,000 <= x, y, z <= 500,000), which are the space coordinates of the planets. The first two coordinates belong to the central broadcasting planets. For convenience, you can assume each planet as a point in space.


After that an integer q (1 <= q <= 500,000 ) will be given, which is the number of transmissions. Each of the following q lines will contain two integers r1 and r2 (1 <= r1, r2 <= 10,000,000), the effective broadcasting radius for first and second broadcasting planet respectively. (The input file is huge. Please use faster input/output methods.)

 

Output

 

For each transmission print the number of planets that particular transmission will reach (excluding the broadcasting planets).

 

Sample Input

Output for Sample Input

5
1 1 1

5 5 5

2 2 2

3 3 3

4 4 4

4
1 1

2 1

2 2

6 6

0

1

2

3

 

 

 

Problemsetter: Iqram Mahmud

Special Thanks: Shiplu Hawlader