Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

E. Exclusive Display
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Seven-segment green colour vacuum fluorescent display tube IV-6. Manufactured in the former Soviet Union, 1985. Image source: Mister rf, Wikimedia Commons, Creative Commons Attribution-Share Alike 4.0 International.

The days-without-incident counter at your factory has become difficult to interpret.

The counter is a single-digit seven-segment display that you bought cheaply in a second-hand hardware store. Each of its seven segments is either off or on, and a digit is shown by turning on the corresponding segments:

$$$\,$$$ $$$\,$$$ $$$\,$$$ $$$\,$$$ $$$\,$$$

$$$\,$$$ $$$\,$$$ $$$\,$$$ $$$\,$$$

Every morning, the display is reset so that all segments are off. When a digit is entered into the display, every segment belonging to that digit is flipped: from off to on, or from on to off. This worked just fine as long as the counter only ever needed to show a single digit.

However, thanks to your diligent work with safety protocols, the number of days without incident now routinely reaches two-digit numbers. Since the display has room for only one digit, a two-digit number is entered by typing its two digits one after the other, into the same display. This may well flip a particular segment off again.

The number of days without incident is called the streak length $$$s$$$ and satisfies $$$0\leq s\leq 99$$$. It is entered without leading $$$0$$$s, so a single-digit streak length is entered as one digit.

Given the state of the display after the streak length has been entered, determine which values of $$$s$$$ could have produced it.

Input

The input consists of:

  • $$$7$$$ lines, each with $$$4$$$ characters, each character being either "." or "#".
The input describes a possible state of the seven-segment display, with two characters used for each of the seven segments. Each segment can be off or on, shown as ".." or "##", respectively, either horizontally or vertically. The parts of the input that don't correspond to segments are always shown as "." for readability.
Output

Output the possible streak lengths, without leading $$$0$$$s. If there is more than one possible streak length, report all of them in sorted order. If no streak length could have resulted in the input display, output "impossible".

Examples
Input
.##.
#..#
#..#
.##.
#..#
#..#
.##.
Output
8
Input
....
....
....
....
#...
#...
....
Output
56
65
89
98
Input
....
....
....
....
....
....
.##.
Output
impossible