Identify the number 数字的组合问题

Problem Description
Taly likes to take photographs. Because he is interested in geometry and graphics. One day, he went to a museum which exhibits all kinds of things of Mars people. He is surprised that the Mars people use the arabic numberals as human beings. But they only use the number from 0 to 8 and they like to write the numbers in a skew style as the gure sees. Then Taly took many photographs of the number writing (in fact,it is forbidden to take photograph in the so mystical museum). When home, he transformed these photograph into the graph on a 2 - D plane. Taly is confused that how to identify the numbers automatically. Now Taly ask help to you to write a program to identify the numbers.

Input
For each test case, the first line is the number n which indicates the number of the segments. Then n lines follow, each line has four float numbers which are x1, y1, x2, y2 with precision up to 6 decimal places. (x1, y1), (x2, y2) are the two endpoints of the segment. Each segment has the same length 1 and one segment connects at least another one. For any line which is paralleled with y-axis and has width of 5, it won't cross more than one number. It means that the minimum absolute dierence of two number's x coordinate is at least 5.
2 ≤ n ≤ 1000, -10000 ≤ x1, y1, x2, y2 ≤ 10000.

Output
For each test case, output the numbers from left to right as the sample sees.

Sample Input
12
-6.000000 2.000000 -6.000000 3.000000
-6.000000 3.000000 -6.000000 4.000000
0.707107 -0.707107 0.000000 0.000000
0.000000 0.000000 0.707107 0.707107
0.707107 0.707107 1.414213 0.000000
1.414213 0.000000 2.121320 0.707107
2.121320 0.707107 1.414213 1.414213
9.707107 -0.707107 9.000000 0.000000
9.000000 0.000000 9.707107 0.707107
9.707107 0.707107 10.414213 0.000000
9.707107 0.707107 10.414213 1.414213
11.121320 0.707107 10.414213 1.414213

Sample Output
123