Billiard#6460

Billiard

1 second
128 megabytes
Very easy

Let be a convex polygon and a point lying strictly outside of the polygon. There are two tangents from to . Let's take the "right" one (related to ) and assume that is the tangent point and is the point symmetrical to if is the center of symmetry. We say r = T(p) and call a billiard transform.

A tangent from point to a convex polygon , where is the tangent point, is called right if for every point u \in G the counter-clockwise rotation from vector to vector is in the interval .

Here is an example which may help you better understand what is. Suppose is a triangle with vertices , , and has coordinates . Then the "right" tangent will pass through vertex , so T(p) = (5, 1). Similarly, T((3, 0)) = (-1, 2), T((3, 2)) = (-1, 0), T((3, 4)) = (-3, -4). In some cases the "right" tangent may touch the polygon not in the vertex, but by the side. If this happens, is undefined. For example, for the former the values T((3, 3)), T((-1, 0)), T((4, -2)) are undefined.

Consider the sequence S(p) = (p, T(p), T(T(p)), \ldots). Depending on the behavior of this sequence, the set of all points outside of the polygon may be divided into three classes:

  1. The sequence is finite (that is, is undefined for its last term ).

  2. The sequence is infinite and periodic, maybe with some preperiod.

  3. The sequence is infinite and non-periodic.

In this problem, the "billiard table", or the figure , is the parallelogram , where O = (0, 0). You are given the coordinates of some "table" and a point strictly outside of it. Find the type of this sequence. If this sequence is periodic (of type ), find the period.

Input

The first line of input contains one integer (1 \leq t \leq 3 \cdot 10^5) which is the number of test cases. Each of the next lines contains six integers x_A, y_A, x_C, y_C, x_p, y_p not exceeding 10^9 by absolute value: the coordinates of points , and . It is guaranteed that is a non-degenerate parallelogram and that lies strictly outside of it.

Output

Print one number per test case. This number should be:

  • if the sequence is finite,

  • Period length if the sequence is periodic,

  • if the sequence is infinite and non-periodic.

Each number must be printed on a separate line.

Examples

Example 1

Loading
Loading