Counting points inside a circle

For each of M circle queries, count how many of N fixed points lie inside or on the circle, printing the count per query.

Hard9GeometryDivide and conquerSortingSimulationNo attempts yetTime limit8sMemory limit512 MB

Problem

There are NN points on the two-dimensional coordinate plane. Write a program that answers the following query.

  • x y r: print how many points lie inside the circle centered at (x,y)(x, y) with radius rr. A point on the circumference counts as inside.

In other words, a point (a,b)(a, b) is counted when (ax)2+(by)2r2(a - x)^2 + (b - y)^2 \le r^2.

Two or more points can share the same coordinate, and each of them is counted separately. A query never adds or removes a point, so the order in which the queries are processed does not change any answer.

Input

The first line contains the number of points NN (1N1000001 \le N \le 100\,000).

Each of the next NN lines contains the coordinates xx and yy of one point, separated by a space (0x,y10000000 \le x, y \le 1\,000\,000).

The next line contains the number of queries MM (1M1000001 \le M \le 100\,000).

Each of the next MM lines contains one query as xx, yy, rr, separated by spaces (0x,y10000000 \le x, y \le 1\,000\,000, 1r10000001 \le r \le 1\,000\,000).

Every number in the input is an integer.

Output

For each query, print the number of points inside the circle on its own line, in the order the queries are given.