Under construction

Still being built. Things may change

Scrambled Digits

Time limit2sMemory limit512 MB

Summary
Given line segments Petya drew, count how many times each of five digits appears, where digits may be scaled and rotated and overlapping segments belong to one digit.
Level

Medium5 of 10

Topics
Sorting, Geometry, Implementation
Solved
No attempts yet

Problem

Little Petya started to learn how to write some digits. He is just learning to write the following 5 digits:

He draws each digit with exactly the same dimensions as the image above, but he may apply zero or more of the following updates:

  • Shrink or expand the width of the digit, keeping the width an integer number of units.
  • Shrink or expand the height of the digit, keeping the height an integer number of units.
  • Rotate the digit clockwise by 90, 180, or 270 degrees.

Shrinking or expanding a digit does not change the thickness of its segments, and it affects the whole digit equally. For example, shrinking or expanding the digit 3 vertically (before rotating it) always keeps the middle horizontal segment exactly in the middle between the other horizontal segments.

Petya writes many digits on an infinite 2D plane and keeps these rules valid:

  • Digits do not touch or overlap each other. The segments of one digit do not touch the segments of another digit.
  • All vertical segments lie on a vertical line with an integer X-value.
  • All horizontal segments lie on a horizontal line with an integer Y-value.
  • All end points have integer coordinates. An end point is a point at the end of a vertical or horizontal segment.

Petya draws digits with line segments. Each segment starts and ends at integer coordinates, and each segment is vertical or horizontal with a positive integer length. Segments may touch or even overlap, but when they do, they belong to the same instance of the same digit (see the second sample test case).

The following image shows some invalid digits that never appear in the input:

The 1 is rotated incorrectly, the middle horizontal segment of the 3 has the wrong length, the middle horizontal segment of the 2 is no longer in the middle, and the 4 is mirrored instead of rotated.

You are given a list of line segments that Petya drew. The input is guaranteed to form only valid digits as described above. Count how many times each digit was drawn.

Input

The first line contains a single integer T, the number of test cases (1 ≤ T ≤ 100). Each test case starts with a line containing an integer N, the number of segments (1 ≤ N ≤ 100,000). Then N lines follow, each containing four integers X1X_1, Y1Y_1, X2X_2, and Y2Y_2, which describe a segment between the points (X1,Y1)(X_1, Y_1) and (X2,Y2)(X_2, Y_2), where 1 ≤ X1, Y1, X2, Y2 ≤ 1,000,000,000.

Output

For each test case, print 5 integers separated by a single space. Each integer is the number of times the corresponding digit was drawn, in the same left-to-right order as the first image.

Hint

The first sample test case shows the first image.

The second sample test case shows the following image. Some segments overlap or touch to form one longer segment.

Examples1

  1. Example 1

    Input
    2
    17
    1 1 1 7
    1 7 4 7
    4 7 4 1
    4 1 1 1
    6 1 6 7
    11 1 8 1
    8 1 8 4
    8 4 11 4
    11 4 11 7
    11 7 8 7
    13 1 16 1
    16 1 16 7
    16 7 13 7
    16 4 13 4
    21 1 21 7
    21 4 18 4
    18 4 18 7
    24
    1 2 1 4
    1 4 1 8
    1 6 1 10
    1 11 4 11
    2 1 2 9
    2 1 3 1
    2 5 3 5
    2 9 3 9
    4 7 4 8
    4 8 5 8
    5 8 5 7
    5 7 4 7
    5 2 5 6
    5 4 8 4
    8 4 8 2
    5 9 5 10
    5 10 6 10
    6 10 6 9
    6 9 7 9
    7 9 7 10
    8 7 8 10
    8 10 9 10
    9 10 9 7
    9 7 8 7
    
    Expected output
    1 1 1 1 1
    2 2 1 1 1