Matchsticks
题号:NC24671
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 64 M,其他语言128 M
64bit IO Format: %lld

题目描述

Have you ever met a Matchstick math puzzle? Some of them are like this:

ADD 3 matchsticks to make the equation true. Negative numbers are not allowed and no number is greater than 9.

Well, Ramen likes such puzzles. The ACM a.k.a. All Champions Matchsticks, which is a contest about solve such puzzles, is going to hold. Ramen want to win a gold medal, so he signed up for this contest.

The subject he applies is solving puzzles about equations like the given one. The rules are pretty simple: contestants will be given some correct or incorrect Matchstick equations. The contestant can do at most one of the below actions:

- Add one matchstick into any elements.
- Remove one matchstick from any elements.

The modify should be valid, in other words, when you add or remove a matchstick, the new item should be a valid element. It will be considered solved if it comes true after making changes. Leave it not changed is also valid. Who is the first one solves all puzzles will win a gold medal, what is Ramen dreams about.

Here is a picture which shows how the numbers are placed in the contest, which may help you understand the situation better.



The puzzles are varied, and some of them are hard. Ramen knows you're good at solving these puzzles too, so he asks you for help.

输入描述:

The input contains multiple test cases.

The first line contains a single integer T(1 <= T <= 1000), represents the number of test cases. 

Then T cases follow.

The first line of each test case contains two integers n(1 <= n <= 99) and p(1 <= p <= 18), represents the number of elements on the left and the right side of the equal sign.

The next 5 lines give an equation; each line contains 6(n+p)+5 characters, represents one part of the equation. There is a space between each element. In this section, each of the 5x5 rectangles forms an element.

Below gives you the corresponding Matchstick representation of the items in the order of . To make it more clear, we use dots(.) to represent spaces. In real input, no dots are included.



You can assume that the input has below guarantees:
- The equation only contains -, |, +, x and spaces.
- There will be only one equal sign in each test case.
- The operands on the left side of the equal sign will be precisely one digit each.
- The right side of the equal sign will be only and exactly one number without leading zeros.
- The result will not exceed the maximum possible value of a 64-bit integer.

输出描述:

For each test case, output Case #x: y, x is the number of the test case(starts from 1), y is Yes if you can modify at most one element of the equation to make it right, otherwise No.
示例1

输入

复制
2
3 2
 ---  \   /  ---        |   |  --- 
|      \ /      | ----- |   | |   |
 ---    x       |        ---   --- 
    |  / \      | -----     | |   |
 ---  /   \     |           |  --- 
3 1
 ---    |    ---         --- 
|       |       | -----     |
 ---  --+--  ---         --- 
    |   |       | ----- |    
 ---    |    ---         ---

输出

复制
Case #1: No
Case #2: Yes

说明

Be careful, please add the necessary spaces when you copy the sample input if there are no spaces at the end of each line. We're sorry for the inconvenience.

备注:

To avoid confusion, the plus, multiply and the equal sign using two matchsticks while the minus sign using only one matchstick.