The Careful Average

City Hall keeps getting neighborhood reports - noise levels, air quality, you name it. But a single report can be misleading. You are asked to help them, but only trust a neighborhood’s average if there are enough reports. Otherwise, fall back to the citywide average.

The first line of the input contains a single integer n, the number of (neighborhood, value) reports.

The next n lines each contain a neighborhood name (no spaces) and an integer value (the number of reports).

The following line contains an integer m, the minimum number of reports required to trust a neighborhood’s own average.

The next line contains an integer q, the number of neighborhoods to predict for.

The next q lines contain a neighborhood name to query.

For each queried neighborhood:

  • If it has at least m reports, print its mean value.

  • Otherwise, print the global mean across all n reports.

Input

Output

6
A 5
A 9
B 7
C 20
C 10
D 3
2
4
A
B
E
D

7
9
9
9

6
A 5
A 9
B 7
C 20
C 10
D 3
1
4
A
B
E
D

7
7
9
3

5
X 2
Y 8
Y 10
Z 4
Z 6
3
3
X
Y
Q

6
9
6

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