Digital Clock

Time limit1sMemory limit128 MB

Problem

The most common component for showing digits in electronic devices is the seven-segment display. A seven-segment display represents a single digit using $7$ segments: $3$ horizontal segments and $4$ vertical segments. Each segment can be lit or unlit and operates independently of the others.

Label the segments as follows.

  • a: top horizontal
  • b: upper-right vertical
  • c: lower-right vertical
  • d: bottom horizontal
  • e: lower-left vertical
  • f: upper-left vertical
  • g: middle horizontal

The digits $0$ through $9$ are shown by lighting the segments listed in the table below.

DigitLit segments
0a, b, c, d, e, f
1b, c
2a, b, d, e, g
3a, b, c, d, g
4b, c, f, g
5a, c, d, f, g
6a, c, d, e, f, g
7a, b, c
8a, b, c, d, e, f, g
9a, b, c, d, f, g

To display several digits at once, you place several seven-segment displays side by side. For example, a clock uses $4$ seven-segment displays to show the hour ($00$–$23$) and the minute ($00$–$59$). A clock therefore has $28$ segments in total.

Hyunsu picked up a broken alarm clock on the street. The clock does not always show the correct time, and Hyunsu believes this is because some of its segments are broken.

A broken segment never lights up. Every other segment works normally. Each of the clock's $28$ segments is either completely broken (never lights under any circumstance) or perfectly working (it lights when it should and stays dark when it should). Which segments are broken does not change during the observation.

Hyunsu wants to know the current time. So, watching the clock, he wrote down the displayed time once per minute. Exactly $1$ real minute passes between two consecutive records. (Because the clock is broken, the displayed time may stay the same for several minutes.)

Given the times Hyunsu wrote down in order, write a program that finds every possible real time at the moment of the first record. As stated, each segment is either completely broken (never lights) or perfectly working (lights when it must and stays dark when it must).

There may be several answers; in that case, find all possible times.

Input

The input consists of several test cases.

Each test case begins with the number of observations $N$ ($1 \le N \le 50$). Then $N$ times follow in the order they were observed. Each time is written in HH:MM format, with the hour and minute as two digits separated by a :.

The shape shown by the seven-segment displays might not be interpretable as a digit from $0$ to $9$, but for unknown reasons this never happens while Hyunsu observes the clock; that is, the four given positions always form valid digit shapes.

Test cases continue until the end of the file.

Output

For each test case, print every possible real time at the first record, in ascending order, separated by spaces on one line. Every printed time must be a valid time (hour $00$–$23$, minute $00$–$59$). If no time is possible, print none.