Only Trust the Neighbors

A cautious field sensor only speaks up when nearby readings agree. At a new spot on the map, it looks around; if no known readings are close enough, it stays quiet and prints unknown. If some are nearby, it blends the voices of up to k closest ones and reports their average. Nearness is measured by straight-line distance on the 2D map.

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

Each of the next n lines contains two floating-point numbers x y followed by a floating-point value v, describing one reading’s position and value.
The next line contains two values: an integer k and a floating-point number D representing the maximum number of neighbors to use and the distance cutoff. Only readings with distance ≤ D are considered.

The next line contains a single integer q representing the number of locations to evaluate.
Each of the last q lines contains two floating-point numbers x y for a location where the sensor wants a prediction.

For each location, print either unknown or the mean of the selected nearby values.

Input

Output

4
0 0 10
2 0 14
0 2 16
-1 -1 8
2 1.5
3
0.5 0.5
0 1
3 3

10
13
unknown

5
0 0 0
0 1 2
1 0 4
1 1 6
2 2 100
3 1.5
2
0.9 0.9
2 2

4
53

3
0 0 1.5
1 0 2.5
0 1 3.5
2 1
3
0.6 0
0.7 0.7
5 5

2
3

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