logo AlgoBeat OnlineJudge
登录 注册

#216524. [GKS 2014 #A] Addition

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 from and .

Alice wanted to test Bob's addition skills. Some equations were given to Bob in form of , , , and Bob has to find out the answers of questions like , , 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. , , . She wants to continue with the checkable equations, e.g. could be concluded by , , , and thus the question 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.

输入格式

The first line of the input gives the number of test cases, . test cases follow.

The first line of each test case contains a single integer : the number of correctly answered questions. Each of the next lines contain one correctly answered question in the form "", where and are names of variables and is a decimal integer.

The next line contains a single integer : the number of remaining questions. Each of the next lines contain one question in the form "", where and are names of variables.

输出格式

For each test case, the first line of output contains "Case #x:", where is the test case number (starting from 1). For each question in the input that was checkable, output a single line with the answer in the form "", where and are names of variables and 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.

样例

样例输入 1

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

样例输出 1

Case #1:
apple+banana=10
apple+banana=10
banana+apple=10
Case #2:
a+d=3
b+c=3

数据范围与提示

Limits

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.

Small dataset (Test set 1 - Visible)

Large dataset (Test set 2 - Hidden)