Digits on the Floor
Taro attempts to tell digits to Hanako by putting straight bars on the floor. Taro wants to express each digit by making one of the forms shown in Figure 1.
Since Taro may not have bars of desired lengths, Taro cannot always make forms exactly as shown in Figure 1. Fortunately, Hanako can recognize a form as a digit if the connection relation between bars in the form is kept. Neither the lengths of bars nor the directions of forms affect Hanako’s perception as long as the connection relation remains the same. For example, Hanako can recognize all the awkward forms in Figure 2 as digits. On the other hand, Hanako cannot recognize the forms in Figure 3 as digits. For clarity, touching bars are slightly separated inFigures 1, 2 and 3. Actually, touching bars overlap exactly at one single point.
Figure 1: Representation of digits
Figure 2: Examples of forms recognized as digits
In the forms, when a bar touches another, the touching point is an end of at least one of them. That is, bars never cross. In addition, the angle of such two bars is always a right angle.
To enable Taro to represent forms with his limited set of bars, positions and lengths of bars can be changed as far as the connection relations are kept. Also, forms can be rotated.
Keeping the connection relations means the following.
Figure 3: Forms not recognized as digits (these kinds of forms are not contained in the dataset)
Separated bars are not made to touch.
Touching bars are not made separate.
When one end of a bar touches another bar, that end still touches the same bar. When it touches a midpoint of the other bar, it remains to touch a midpoint of the same bar on the same side.
The angle of touching two bars is kept to be the same right angle (90 degrees and −90 degrees are considered different, and forms for 2 and 5 are kept distinguished).
Your task is to find how many times each digit appears on the floor.
The forms of some digits always contain the forms of other digits. For example, a form for 9 always contains four forms for 1, one form for 4, and two overlapping forms for 7. In this problem, ignore the forms contained in another form and count only the digit of the "largest" form composed of all mutually connecting bars. If there is one form for9, it should be interpreted as one appearance of 9 and no appearance of 1, 4, or 7.
Input
The input consists of a number of datasets. Each dataset is formatted as follows.
n
x_1a y_1a x_1b y_1b
x_2a y_2a x_2b y_2b
...
x_na y_na x_nb x_nb
In the first line, n represents the number of bars in the dataset. For the rest of the lines, one line represents one bar. Four integers x_a, y_a, x_b, y_b, delimited by single spaces, are given in each line. x_a and y_a are the x- and y-coordinates of one end of the bar, respectively. x_b and y_b are those of the other end. The coordinate system is as shown in Figure 4. You can assume 1 ≤ n ≤ 1000 and 0 ≤ x_a, y_a, x_b, y_b ≤ 1000.
The end of the input is indicated by a line containing one zero.
Figure 4: The coordinate system
You can also assume the following conditions.
More than two bars do not overlap at one point.
Every bar is used as a part of a digit. Non-digit forms do not exist on the floor.
A bar that makes up one digit does not touch nor cross any bar that makes up another digit.
There is no bar whose length is zero.
Output
For each dataset, output a single line containing ten integers delimited by single spaces. These integers represent how many times 0, 1, 2, ..., and 9 appear on the floor in this order. Output lines must not contain other characters.