Cauldron Classifier: Skim the Gremlins, Ask Five

In the Potion Lab, three sensors watch each brew: hue, temperature, and viscosity. Sometimes a gremlin bumps a dial, and readings fly out of the realm of plausible potions. Your sorter should ignore impossible measurements and then ask the closest five known brews what the new sample most resembles.

You are asked to read an initial list of labeled brews, use the given valid ranges to drop any initial row where any feature is outside its allowed interval, and then classify new brews with 5-NN using Euclidean distance for those 3 features. If votes tie, print the alphabetically smallest label. Assume at least five rows remain after filtering.

The first line of the input contains a single integer n representing how many labeled brews are in the initial list. The second line contains six floating-point numbers: the minimum and maximum for each feature in order: hue_min hue_max temp_min temp_max visc_min visc_max. Each of the next n lines contains three floating-point numbers and a label with no spaces: hue temperature viscosity label.

The next line contains a single integer q representing how many new brews to classify. Each of the next q lines contains three floating-point numbers: hue temperature viscosity - to be classified after filtering the initial list by the given ranges.

The program should print q lines. Each line should contain the predicted label for the corresponding new brew.

Input

Output

10
0 360 10 120 0.1 5.0
30 25 0.50 ELIXIR
45 30 0.60 ELIXIR
60 35 0.55 ELIXIR
200 80 2.00 TONIC
210 85 2.20 TONIC
220 90 2.10 TONIC
330 20 4.60 HEX
340 15 4.50 HEX
345 18 4.40 HEX
999 999 999 GLITCH
3
50 32 0.58
215 88 2.10
335 19 4.55

ELIXIR
TONIC
HEX

10
0 360 10 120 0.1 5.0
35 28 0.60 ELIXIR
45 32 0.55 ELIXIR
50 38 0.65 ELIXIR
205 80 2.00 TONIC
220 90 2.10 TONIC
230 95 2.30 TONIC
330 20 4.60 HEX
345 18 4.50 HEX
355 22 4.30 HEX
1000 1000 1000 GLITCH
3
48 32 0.65
225 86 2.20
340 19 4.30

ELIXIR
TONIC
HEX

7
0 360 15 120 0.1 5.0
27 21 0.52 ELIXIR
210 85 2.00 TONIC
220 92 2.10 TONIC
230 95 2.30 TONIC
340 18 4.40 HEX
-5 20 0.50 OOPS
700 200 10.0 OOPS
1
222 90 2.15

TONIC

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