Billiard
Let G be a convex polygon and p a point lying strictly outside of the polygon. There are two tangents from p to G. Let's take the "right" one (related to p) and assume that q is the tangent point and r is the point symmetrical to p if q is the center of symmetry. We say r = T(p) and call T a billiard transform.
A tangent pq from point p to a convex polygon G, where q is the tangent point, is called right if for every point uG the counter-clockwise rotation from vector to vector is in the interval [0, ).
Here is an example which may help you better understand what T is. Suppose G is a triangle with vertices (0, 0), (2, 0), (1, 1) and p has coordinates (-1, -1). Then the "right" tangent will pass through vertex (2, 0), 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, T(p) is undefined. For example, for the former G the values T((3, 3)), T((-1, 0)), T((4, -2)) are undefined.
Consider the sequence S(p) = (p, T(p), T(T(p)), ...). Depending on the behavior of this sequence, the set of all points p outside of the polygon may be divided into three classes:
The sequence S(p) is finite (that is, T(v) is undefined for its last term v).
The sequence S(p) is infinite and periodic, maybe with some preperiod.
The sequence S(p) is infinite and non-periodic.
In this problem, the "billiard table", or the figure G, is the parallelogram OABC, 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 2), find the period.
Input
The first line of input contains one integer T (1 ≤ T ≤ 3·10^5) which is the number of test cases. Each of the next Tlines 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 A, C and p. It is guaranteed that OABC is a non-degenerate parallelogram and that p lies strictly outside of it.
Output
Print one number per test case. This number should be:
-1 if the sequence is finite,
Period length if the sequence is periodic,
-3 if the sequence is infinite and non-periodic.
Each number must be printed on a separate line.