G(x)

Time Limit: 500ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 4733
64-bit integer IO format: %I64d      Java class name: Main

Description

For a binary number x with n digits (AnAn-1An-2 ... A2A1), we encode it as
Where "" is bitwise XOR operation and "" indicates the largest integer which is not greater than x.
Due to some reasons, Mzry1992 encode his password P into G(P), and additionally, he encode P + 1 into G(P + 1) too, and write G(P) and G(P + 1) into his diary.
This story happened many years ago and now you hold the diary with these numbers in your hands. Unfortunately, some digits are unreadable now. Could you determine the values of these digits using the readable digits?

Input

The first line has a number T (T <= 100) , indicating the number of test cases.
For every test case, it has 2 lines of same number of digits describe G(P) and G(P + 1), In every line, it only contains 1, 0 and ?. Unreadable digits are denoted with symbol ?, The length of every line in the input is up to 105.

Output

For every case, you should output "Case #t: " at first, without quotes. The t is the case number starting from 1.
Then, if there is impossible to restore G(P) and G(P + 1), you should output "Impossible" in the second line.
Otherwise, if G(P) is unique, you should output restored G(P) and G(P +1) in the same format.
Otherwise, you should output "Ambiguous" and the number of possible G(P) in the second line.
The number may be very large so the answer should modulo 10^9 + 7.

Sample Input

3
10??
10??
0010
0110
1?01
0?01

Sample Output

Case #1:
Ambiguous 3
Case #2:
0010
0110
Case #3:
Impossible

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .