Digits on the Floor

Time limit2sMemory limit128 MB

Problem

Taro tells digits to Hanako by laying straight bars on the floor. He forms each digit as one of ten fixed shapes, drawn in the style of a seven-segment display.

Because Taro may not have bars of exactly the right lengths, he cannot always lay the shapes out perfectly. Fortunately, Hanako recognizes a shape as a digit as long as the connection relation between its bars is preserved. Neither the lengths of the bars nor the overall orientation of a shape matters to her, only how the bars are connected. So she can still read stretched or rotated shapes as digits, while she rejects shapes whose connections match no digit.

When one bar touches another, the touching point is an endpoint of at least one of them, and the two bars overlap at exactly one single point; bars never cross, and two touching bars always meet at a right angle. Positions, lengths, and the overall rotation of a shape may change freely, as long as the connection relations are kept. Keeping the connection relations means:

  • Separated bars are never brought into contact.
  • Touching bars are never separated.
  • If an endpoint of a bar touches another bar, that endpoint keeps touching the same bar; if it touches an interior point of the other bar, it keeps touching an interior point of the same bar on the same side.
  • The right angle between two touching bars keeps its sign: a $+90°$ corner and a $-90°$ corner are considered different, so the shapes for 2 and 5 stay distinguishable.

The ten shapes are the ones shown in the original figure. Described in words, each digit is built from straight bars as follows (the words top, bottom, left, right, and middle refer to the segments of a seven-segment display):

  • 0 — four bars forming a rectangle: a top bar, a bottom bar, a full-height left bar, and a full-height right bar.
  • 1 — a single vertical bar (the right side).
  • 2 — five bars in a zigzag: a top bar, then a bar down the upper right, a middle bar running left, a bar down the lower left, and a bottom bar running right.
  • 3 — four bars: a top bar, a full-height right bar, a bottom bar, and a middle bar that touches the right bar at an interior point.
  • 4 — three bars: an upper-left vertical bar, a full-height right bar, and a middle bar that meets the upper-left bar at one end and touches the right bar at an interior point.
  • 5 — the mirror image of 2, also five bars: a top bar, then a bar down the upper left, a middle bar running right, a bar down the lower right, and a bottom bar running left.
  • 6 — five bars: a top bar, a full-height left bar, a bottom bar, a lower-right vertical bar, and a middle bar that touches the left bar at an interior point.
  • 7 — three bars: a top bar, a short vertical tick hanging down from its left end, and a full-height right bar.
  • 8 — five bars: the four sides of a rectangle, plus a middle bar that touches both the left bar and the right bar at interior points.
  • 9 — four bars: a top bar, an upper-left vertical bar, a full-height right bar, and a middle bar that touches the right bar at an interior point.

Some digit shapes always contain the shapes of other digits. For example, a shape for 9 always contains four shapes for 1, one shape for 4, and two overlapping shapes for 7. Ignore any shape contained inside a larger one, and count only the largest shape formed by each maximal group of mutually connected bars. A single 9 counts as one 9 and adds nothing to the counts of 1, 4, or 7.

Your task is to count how many times each digit appears on the floor.

Input

The input consists of several datasets. Each dataset has the following form:

n
xa_1 ya_1 xb_1 yb_1
xa_2 ya_2 xb_2 yb_2
.
.
.
xa_n ya_n xb_n yb_n

The first line contains $n$, the number of bars. Each of the next $n$ lines describes one bar with four integers $xa$, $ya$, $xb$, $yb$ separated by single spaces: $(xa, ya)$ and $(xb, yb)$ are the coordinates of the two ends of the bar, given in a fixed Cartesian coordinate system. You may assume $1 \le n \le 1000$ and $0 \le xa, ya, xb, yb \le 1000$.

The end of the input is a line containing a single zero.

You may also assume the following:

  • No point is shared by more than two bars.
  • Every bar is part of some digit; there are no non-digit shapes on the floor.
  • No bar of one digit touches or crosses any bar of another digit.
  • No bar has length zero.

Output

For each dataset, print a single line containing ten integers separated by single spaces. These integers are the numbers of times the digits $0, 1, 2, \ldots, 9$ appear on the floor, in that order. Print no other characters.