Confidence Meter

A music app places listeners on a 2D taste map. It already knows a few listeners and whether they liked a song (1) or not (0). For a new listener position, the app looks at the k closest known listeners using straight-line distance (Euclidean L2) and reports how confident it is: the percentage of those k neighbors with label 1.

You are asked to implement that feature in the app.

The first line of the input contains a single integer n representing the number of known listeners.

The next n lines each contain two floating-point numbers x y followed by a label 0 or 1, describing one listener’s position and whether they liked the song.

The next line contains a single integer k (1 ≤ k ≤ n).

The next line contains a single integer q representing the number of listener positions to check.

The last q lines each contain two floating-point numbers x y representing the coordinates of new listeners.

The program should print q  lines, each one representing the percentage of 1s for each new listener.

Input

Output

5
0 0 1
2 0 0
0 2 1
2 2 0
1 1 1
3
0.9 0.9
1.1 1.1
2 1

66.66666666666667
33.333333333333336
33.333333333333336

4
0 0 1
0 1 1
1 0 1
3 3 0
4
2
0.1 0.1
1 0.9

75
75

4
0 0 0
0 1 0
1 0 0
3 3 1
4
2
0.2 0.2
3 3

25
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