403425: GYM101156 M Addition

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

M. Additiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Six years ago, a robot, Bob, with infant's intelligence has been invented by an evil scientist, Alice.

Now the robot is six years old and studies in primary school. Addition is the first operation he learned in math. Due to his strong reasoning ability, he could now conclude a + b = 12 from a = 2 and b = 10.

Alice wanted to test Bob's addition skills. Some equations were given to Bob in form of a = 2, b = 10, c = 4, and Bob has to find out the answers of questions like a + b, a + c, etc.

Alice checked Bob's answers one by one in the test papers, and no mistake has been found so far, but Alice lost the given equations after a cup of coffee poured on them. However she has some of Bob's correct answers, e.g. a + b = 12, a + c = 6, c + d = 5. She wants to continue with the checkable equations, e.g. b + d = 11 could be concluded by a + b = 12, a + c = 6, c + d = 5, and thus the question b + d is checkable.

To prevent the artificial intelligence technology from being under the control of Alice, you disguised yourself as her assistant. Now Alice wants you to figure out which of the rest of questions are checkable and their answers.

Input

The first line contains a single integer n (1 ≤ n ≤ 5000): the number of correctly answered questions. Each of the next n lines contain one correctly answered question in the form "x+y=z", where x and y are names of variables and z ( - 200000 ≤ z ≤ 200000) is a decimal integer.

The next line contains a single integer q (1 ≤ q ≤ 5000): the number of remaining questions. Each of the next q lines contain one question in the form "x+y", where x and y are names of variables.

Names of variables are strings of lowercase English letters. Each name contains at most 10 characters.

There is no contradiction in the answered questions and if the answer is checkable, the result is an integer.

Output

For each question in the input that was checkable, output a single line with the answer in the form "x+y=z", where x and y are names of variables and z is a decimal integer. Questions should be listed in the same order as they were given in the input. Please do NOT ignore duplicated questions, since Alice would fire you if you pointed any mistake of hers.

ExamplesInput
2
apple+banana=10
coconut+coconut=12
5
apple+banana
apple+banana
apple+apple
banana+apple
peach+apple
Output
apple+banana=10
apple+banana=10
banana+apple=10
Input
3
a+b=3
b+c=3
c+d=3
4
a+c
a+d
b+c
b+d
Output
a+d=3
b+c=3

加入题单

算法标签: