Two Votes, One Package

A busy shipping desk must choose between express and economy, using two clues - weight (in kilograms) and distance (in kilometers). Raw distances are dominated by kilometers; after scaling, kilometers and kilograms speak equally. The same parcel can get two different verdicts - and the desk wants to see both.

You are asked to read an initial list of labeled parcels and then, for each new parcel, print two labels: first, the prediction from 3-NN on the raw features, second, the prediction from 3-NN after min-max scaling computed from the initial list only. Use Euclidean distance for neighbor search. If a feature is flat in the initial list, its scaled value is 0 for all rows. If neighbor labels tie, print the alphabetically smallest label.

The first line of the input contains a single integer n representing how many parcels are in the initial list. Each of the next n lines contains two floating-point numbers and a label with no spaces - weight distance label.

The next line contains a single integer q representing how many new parcels to decide on. Each of the next q lines contains two floating-point numbers - weight distance.

The program should print q lines. Each line should contain two labels, separated by a space: the raw 3-NN decision, followed by the scaled 3-NN decision.

Input

Output

6
1 900 economy
2 850 economy
3 820 economy
8 60 express
9 70 express
10 50 express
2
1 100
9 600

express economy
economy express

8
2 700 economy
1.5 750 economy
3 820 economy
7 120 express
8 100 express
10 80 express
6 140 express
2.5 900 economy
3
2 130
7.5 100
3 800

express express
express express
economy economy

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