Intersection Points

No attempts yetTime limit1sMemory limit256 MB

Problem

For an axis-aligned rectangle and a line segment, count how many points lie on both the rectangle boundary and the segment. Print 4 when the segment overlaps the boundary and there are infinitely many intersection points.

Input

The first line contains TT. Each test case gives a rectangle by (xmin,ymin)(x_{min}, y_{min}) and (xmax,ymax)(x_{max}, y_{max}), then a segment from (x1,y1)(x_1,y_1) to (x2,y2)(x_2,y_2).

Output

For each test case, print the finite intersection count, or 4 when the intersections are infinite.