Under construction

Still being built. Things may change

Restoring the Erased Equation (Large)

Time limit5sMemory limit512 MB

Summary
Fill every ? with a digit so the addition or subtraction holds without leading zeros and the whole equation is lexicographically smallest.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Math
Solved
No attempts yet

Problem

A publisher made an arithmetic practice book for elementary school students. A rival publisher secretly edited the manuscript right before printing and erased some of the digits in the equations. The erased positions have to be filled back in.

An equation follows these rules.

  • An equation has the form number operator number = number.
  • The operator is addition + or subtraction -.
  • Every number is a non-negative integer. A number with two or more digits does not start with 0, and zero is written as the single digit 0.
  • Each erased position is shown as one ? character.
  • Replacing a ? with a digit does not change how many digits a number has.
  • There is exactly one space between a number and the operator, and between a number and =. The equation has no spaces at its start or end.
  • The equation was correct before the digits were erased, so at least one restoration satisfies every rule.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains the equation of one test case.

Limits

  • 1≤T≤1001 \le T \le 100
  • 1≤1 \le length of an equation ≤250\le 250

Output

For each test case, print one line in the form Case #x: y, where x is the case number starting from 1 and y is the restored equation.

If several restorations are possible, compare the whole equation as a string and print the smallest one in lexicographic order. For example, ? + ? = 2 can be restored as 0 + 2 = 2, 1 + 1 = 2, or 2 + 0 = 2, so the answer is 0 + 2 = 2.

Examples3

  1. Example 1

    Input
    3
    1?3 + 24? = 424
    3 + ? = 9
    1? - ? = 3
    
    Expected output
    Case #1: 183 + 241 = 424
    Case #2: 3 + 6 = 9
    Case #3: 10 - 7 = 3
    
  2. Example 2

    Input
    4
    ? + 0 = 0
    ?0 + ?0 = 100
    ?? + ?? = 100
    ?? - ?? = 0
    
    Expected output
    Case #1: 0 + 0 = 0
    Case #2: 10 + 90 = 100
    Case #3: 10 + 90 = 100
    Case #4: 10 - 10 = 0
    
  3. Example 3

    Input
    4
    9? + ? = 100
    ?? - ? = ?
    100? + ??? = 1???
    ?9 - 9? = ?
    
    Expected output
    Case #1: 91 + 9 = 100
    Case #2: 10 - 1 = 9
    Case #3: 1000 + 100 = 1100
    Case #4: 99 - 90 = 9