Ask Three Neighbors

A new café wants to match the neighborhood vibe. It knows where other cafés are and what roast they serve: light, medium, or dark. For each possible location, it will ask the three closest cafés and go with the majority. Distances are measured with straight-line distance.

cafes.jpg

The first line of the input contains a single integer n representing the number of known cafés.

The next n lines each contain two floating-point numbers x y followed by a roast word (for example, light, medium, or dark), describing one café’s position and roast.

The next line contains a single integer q representing the number of candidate locations to check.

The last q lines each contain two floating-point numbers x y for the candidate location.

For each candidate location, find the three nearest known cafés, take a majority vote over their roasts, and print the winning roast. If several roasts are tied for the most votes, print the alphabetically smallest roast among them.

Input

Output

5
0 0 light
2 0 medium
0 2 medium
-2 0 dark
0 -2 light
3
0.5 0.5
1.6 0.2
-1.5 0

medium
medium
dark

4
0 0 medium
3 0 light
0 3 light
-3 0 dark
2
1 1
2.6 0.1

light
light

3
0 0 dark
0 2 light
2 0 medium
2
1 1
0.9 1.1

dark
dark

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue