University Grade Manager

University Grade Manager

No dataset at present.

Background

As approaching the end of the term, grade recording becomes a hard work. The officiers hope to have a program that can automatically acquire grade and give the needed data of the grade. Please help him/her do it.

Description

You will firstly be given n lines. Each lines, there will be four elements, describing department(string), course(string), name(string), grade(number). These four elements are divided by a space. For example, JI VG101 W 50 means that student W from JI department gets 50 points in the course VG101.

Then, there will be m lines describing m requests. Each line, there will be 1 to 3 elements, with form 'a', 'a b', 'a b c', where a always refer to the department, b always for course name, and c for the student name. No other order of these elements will appear. An average of all the grade that satisfying the request (the grade is owned by a student in a department (b course) (calling c)) is needed to be output.

Check the I/O format for detailed informaiton.

Format

Input

First a number n. Then followed by n lines.
Each line in the format department(string), course(string), name(string), grade(number).
Then a number m. Then followed by m lines.
Each line has 1, 2, or 3, elements, describing department(string), course(string), name(string). (if name appear, course must appear; if course appear, department must appear, and the order is the same as the previous input.)

Output

Output m lines, describing the average of the grade for the given request.

Sample 1

Input

4
JI VG101 Li 98
CoE VE311 Lucky 50 
JI VG101 Yuan 96
JI Vv557 Jiaren 100
3
JI
JI VG101
JI Vv557 Jiaren

Output

98
97
100

Information

Difficulty
(None)
Category
(None)
Tags
(None)
# Submissions
0
Accepted
0
Accepted Ratio
?
Uploaded By