Ice Igloos

Count how many of up to 100000 small disjoint circles each of up to 100000 query segments passes through.

Medium7GeometryMatrixNo attempts yetTime limit10sMemory limit512 MB

Problem

A fishing village built on the surface of a frozen lake in the far north is in danger from global warming: cracks are starting to form on the lake surface. The village consists of nn igloos of spherical shape, and each igloo covers a circular area of the surface.

An igloo can be represented as a circle in the coordinate plane. The centre of the circle is a point with integer coordinates, and the radius is a positive real number smaller than 11 with exactly one digit after the decimal point.

Given the locations of possible cracks, the villagers want to know how many igloos each crack affects. Formally, you are given qq queries, and each query is a line segment defined by its two endpoints. For each segment, find the number of igloos it intersects. A segment intersects an igloo if the segment and the interior of the circle share at least one point.

Input

The first line contains an integer nn (1n1000001 \le n \le 100\,000), the number of igloos. Each of the next nn lines contains three numbers xx, yy and rr, the coordinates of the centre and the radius of one igloo. The coordinates xx and yy are integers with 1x,y5001 \le x, y \le 500, and rr is a real number with exactly one digit after the decimal point such that 0<r<10 < r < 1. No two igloos overlap or touch.

The next line contains an integer qq (1q1000001 \le q \le 100\,000), the number of queries. Each of the next qq lines contains four integers x1x_1, y1y_1, x2x_2, y2y_2 (1x1,y1,x2,y25001 \le x_1, y_1, x_2, y_2 \le 500), the coordinates of the two endpoints of one segment. The two endpoints are different. An endpoint may lie inside an igloo.

For every igloo ii and every segment ss, the square of the distance between ss and the centre of ii is either smaller than r2105r^2 - 10^{-5} or greater than r2+105r^2 + 10^{-5}, where rr is the radius of igloo ii.

Output

Print qq lines. The kk-th line contains the number of igloos that the kk-th segment intersects.

Hint