Under construction

Still being built. Things may change

Mystery Square (Small)

Time limit5sMemory limit512 MB

Summary
Fill each ? in the binary string with 0 or 1 so the result is a perfect square.
Level

Easy3 of 10

Topics
Brute force, Math
Solved
No attempts yet

Problem

I wrote down a large perfect square in binary, then replaced some of its digits with question marks. Work out what my original number was.

Input

The first line of the input gives the number of test cases, TT. The next TT lines each contain one test case: a string SS, a perfect square written in binary with some of its digits replaced by question marks.

Output

For each test case, print one line in the form Case #x: N, where x is the test case number starting from 1 and N is a perfect square written in binary, obtained by replacing each '?' in SS with either '0' or '1'.

Constraints

  • 1≤T≤251 \le T \le 25
  • SS begins with '1'.
  • SS contains only the characters '0', '1' and '?'.
  • In every test case there is exactly one possible choice for N.
  • SS is at most 60 characters long.
  • SS contains at most 20 '?' characters.

Examples2

  1. Example 1

    Input
    3
    1???
    1
    10??110??00??1000??
    
    Expected output
    Case #1: 1001
    Case #2: 1
    Case #3: 1011110110000100001
    
  2. Example 2

    Input
    9
    1
    100
    1??1
    1?0?
    10000
    1001?0
    1100100
    1?1?1??1
    1??00?00
    
    Expected output
    Case #1: 1
    Case #2: 100
    Case #3: 1001
    Case #4: 1001
    Case #5: 10000
    Case #6: 100100
    Case #7: 1100100
    Case #8: 10101001
    Case #9: 11000100