Putt Party II


Submit solution

Points: 1
Time limit: 1.0s
Python 6.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

Rory and Tony are back at it again at the putt-putt golf course. Rory managed to win last time, but Tony is back on the grind to reclaim his throne. This time, they are on a more advanced course. Similarly, the golf course is a two-dimensional plane, with the tee at (0,0). This time, however, each bumper has different radii, as there are different difficulties of bumpers in different sections. Additionally, Tony has developed a better aim: instead of just hitting the ball at an integer angle, Tony now hits the ball in the direction of some point in the distance with integer coordinates, so he has more fine-grained control over his shots.

Just like before, Tony wants you to test out his various shots and see which ones will miss all the bumpers, and which ones will intersect, and where, with one of the bumpers. Can you help Tony claim his revenge over the upstart Rory?

Input

The first line consists of a single integer n (1\leq n\leq 10^5), the number of bumpers.

The next n lines each contain three space-separated integers x_i, y_i and r_i. The position of each of the bumpers are denoted by x_i and x_y (-10^6 \leq x_i,y_i \leq 10^6), while the radius of the ith bumper around its centre is given by r_i (1 \leq r_i \leq 1000). It is guaranteed that none of the bumpers are repeated or intersect the origin.

The next line contains a single integer q (1 \leq q \leq 10^5), the number of different shots that Tony wants to try.

The next q lines contain two space-separated integers x_j and y_j (-10^6 \leq x_j, y_j \leq 10^6), the coordinates which Tony is aiming his jth shot at. The shot will travel from the tee straight in the direction of this point (x_j,y_j) for the jth shot. It is guaranteed that x_j and y_j are coprime, i.e. they have no common factors besides 1.

It is guaranteed that the bumpers will intersect at no more than 5000 unique points.

Output

For each of the q shots, output if it will hit or miss a bumper.

If it will hit a bumper, output 'HIT' on a line along with the distance the ball will have travelled before it hits the first bumper. This distance should be rounded to 4 decimal places.

If it will hit no bumpers, output 'MISS'.

Example

Input 1
3
4 0 2
-5 -5 2
0 10 3
4
2 1
0 -1
0 1
-2 -3
Output 1
HIT 2.6833
MISS
HIT 7.0000
HIT 5.4926

The first shot intersects the bumper centred at (4,0) at point (2.4,1.2), which is at a distance of approximately 2.6833 from the tee. The second shot is straight in the -y direction, which has no bumpers. The third shot is straight in the +y direction, which is perfectly centred at the bumper at (0,10). This bumper has a radius of 3, so the intersection is 7 along the ball's path. The fourth shot intersects the bumper at (-5,-5).

The bumpers and shots are visualised below:

Image 1

Input 2
3
4 0 2
-5 -5 2
0 10 3
4
2 1
1 -4
0 1
-2 -3
Input 2
9
2 1 1
1 2 1
4 -2 1
2 -3 1
-5 -2 2
-2 -5 2
-3 3 2
-3 3 1
-3 3 3
9
1 1
1 0
0 1
1 -1
3 -2
6 -5
1 -3
-1 -2
-1 3
Output 2
HIT 1.4142
HIT 2.0000
HIT 2.0000
HIT 2.8284
HIT 3.6056
MISS
HIT 3.1623
HIT 3.4172
HIT 1.4709

The bumpers and shots are visualised below:

Image 2


Comments

There are no comments at the moment.