Problem D

What's a Duck Worth?

The siblings Dewey, Huey, and Louie Duck each got $100 from Scrooge McDuck. Being generous siblings, they give each other money on many occasions. However, since they often stuff their change in any pocket they can find (which has caused the washing machine to misbehave on more than one occasion), they have no clue how much money they actually have. Their uncle Donald suggested them to take a course on programming at the University of Oregan, where Donald is college football's most lovable mascot, so that they could develop an app to keep track of their money. However, Dewey, Huey, and Louie prefer to indulge themselves in the activities of the Junior Woodchucks (and let's not fool ourselves, wouldn't you if you ever got a chance?). As a result, you are asked to develop the app.


Source: DuckTales (Disney)

Input

The first line of the input file will consist of a single integer n (1 <= n <= 100). Following this will be n input instances. Each instance will start with a line consisting of two integers: t (1 <= t <= 100) and q (1 <= q <= 100). This line is followed by t lines, each describing a transaction. Each transition has the following format:
n gave m d
where n and m are names consisting of 2 to 10 characters and 1 <= d <= 20. These lines are followed by q lines of queries, each containing a name consisting of 2 to 10 characters.

Output

For each query, which is the name of a sibling, the answer is printed on a separate line (the answer is the amount the sibling has after all transaction have been performed).

Sample Input

2
5 3
Huey gave Dewey 10
Dewey gave Louie 8
Huey gave Louie 12
Louie gave Dewey 5
Louie gave Huey 3
Dewey
Huey
Louie
2 5
Eider gave Quackmore 50
Eider gave Quackmore 50
Eider
Daphne
Eider
Quackmore
Eider

Sample Output

107
81
112
0
100
0
200
0