Axis cores went on many dates with their girl-friends during valentine's week. However CybherGhost, the treasurer has a suspicion that the the other members might have used the money earned in sponsorship on their dates. However he is not sure.
The data is stored in the database as follows:
It has two fields ,
a string s followed by an integer p
The string is created by encrypting the date of transaction concatenated by the encrypted name of the core-member.
The second field consist of the transaction amount which is not encrypted.
Treasurer with the help of S.H.E.L.L club members was able to find the encrypted form of the dates of the transaction however failed to find the encrypted form of the name of the core-members.
Now treasurer wishes to find the total money spent on a specific day.
Help him to find the same.
INPUT:-
First line consists an integer n which gives the count of rows in the database.
For next n lines, a string s and an integer p will be given.
string s is generated as explained above.
Next line consists of an integer q representing number of queries .
For next q lines, a string x will be given.
OUTPUT:
For each query, you need to tell the total amount of money spent on the day whose date is encrypted as string x.
CONSTRAINTS:-
1<=n<=10000
1<=q<=1000
Example :
If eshuKubs withdrew 10000 rupees on 14th Feb, such a transaction is encoded as "abcdxyz 10000" (string without quotes).
If Vickjosh withdrew 4000 rupees on 14th Feb,such a transaction can is encoded as "abcdpqr 4000"
if eshuKubs withdrew 2000 rupees on 13th Feb, such a transaction is encoded as "dfjsdkfjlksjxyz 2000"
if Vickjosh withdrew 2000 rupees on 13th Feb, such a transaction is encoded as "dfjsdkfjlksjpqr 2000"
That is the prefix of the encoded string will match the encrypted string for the date of the transaction.