Min-Max Scaling: Fair Fit, Fair Price

You run a tiny startup that matches shoppers to shoes using KNN. Each person is described by two features - foot length in centimeters and budget in dollars. Dollars swamp centimeters, so KNN can’t judge fairly. To restore balance, you decide to scale both features to the same range before comparing people.

You are asked to read some preexisting data and then scale new entries. Compute the minimum and maximum for each column using the preexisting data only, then transform every new row so that each column lies in the range [0,1]:

If a column (either foot length or budget) in the preexisting data is flat (all values are equal), its scaled value is for every new row.

The first line of the input contains a single integer n representing how many rows of preexisting data you have. Each of the next n lines contains two floating-point numbers: foot length in centimeters and budget in dollars.

The next line contains a single integer q representing how many new rows you want to scale. Each of the next q lines contains two floating-point numbers: foot length and budget - to be scaled using the min and max computed from the preexisting data.

The program should print q lines. Each line should contain two floating-point numbers - the scaled foot length and the scaled budget for the corresponding new row.

Input

Output

3
2 10
4 14
6 18
2
3 12
6 18

0.25 0.25
1 1

2
24 100
26 100
2
25 100
26 100

0.5 0
1 0

4
23.5 40
24 55
25 60
26.5 80
3
24 60
26.5 80
25.5 50

0.1666666667 0.5
1 1
0.6666666667 0.25

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