563 - NTHU_TPC_personal04 Scoreboard

Time

2014/01/23 09:40:00 2014/01/23 13:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
3128 (*) Overlapping Squares
3142 (*) Another n-Queen Problem
3269 Balancing the Scale
9296 Alphametics

3128 - (*) Overlapping Squares   

3142 - (*) Another n-Queen Problem   

3269 - Balancing the Scale   

9296 - Alphametics   

Description

Alphametics, is a type of mathematical game consisting of a mathematical equation among unknown numbers, whose digits are represented by letters. The goal is to identify the value of each letter.

For example:
        S E N D
+     M O R E
------------------------------------------
= M O N E Y
The solution to this puzzle is O = 0, M = 1, Y = 2, E = 5, N = 6, D = 7, R = 8, S = 9
- From Wikipedia

Now, we will give you the puzzle, you should calculate the puzzle’s minimum output. The detail you can find in the sample.

In this question, there are some limitations:
1. The leading digit should not be zero.
2. Each letter should represent different number.
3. If there are several possible output, you should print the minimum one.
4. Each input output length is less than or equal to 10.

Input

The first line will be an integer T(T<=40), which means the number of testcase.
Follow a blank line, there are T testcases.


Each testcase has three lines. The first and second line are the puzzle’s input, the third line is the puzzle’s output. Each length is less than or equal to 10. All the input character will between 'A' to 'Z'.


Every testcase is separated by a blank line.

Output

You should output the minimum output for that puzzle. The answer will quaranted fit in 32 bit number.

In the first sample, A=1,B=2 is the answer. A=2,B=4 is also ok, but we should output the minimum, so the answer is 2.

Sample Input  Download

Sample Output  Download

Tags




Discuss