Vicinity#6939

Vicinity

1 second
64 megabytes
Very hard

This is one of the most basic geometry proximity problems. We are given points in the plane and we should determine which points are in the vicinity of a particular point.

Let the set of points P = \{p_1, p_2, \ldots, p_n\}, where p_i has coordinates (x_i, y_i). We use d(p_i, p_j) to denote the distance between the two points. A point p_j is in the vicinity of point p_i if d(p_i, p_j) \leq d_v. We may call d_v the vicinity distance. Given a set of points , point p_i and d_v, your task is to write a program to calculate the number of points which are in the vicinity of point p_i.

Input

The first line contains an integer (2 \leq n \leq 1000) which determines the number of points. The following lines contain two integers which correspond to the coordinates (x_i, y_i) of each point (-10^6 \leq x_i, y_i \leq 10^6). Then, the following line includes (1 \leq t \leq 50) indicating the number of test cases, followed by lines and each line contains positive integers (1 \leq i \leq n) and d_v (1 \leq d_v \leq 100) which indicate the point p_i and its vicinity distance, respectively.

Output

For each test case, print out in a line the number of points in the vicinity of the corresponding point.

Examples

Example 1

Loading
Loading