Skinny Polygon

For each pair (xbb, ybb), output four vertices of the prescribed skinny polygon: Q1 built from the modular inverse of ybb/g mod xbb/g when 2g <= p+q, otherwise Q2.

Medium7MathNumber theoryGeometryImplementationNo attempts yetTime limit3sMemory limit512 MB

Problem

Two integers xbbx_{bb} and ybby_{bb} are given. Call a polygon skinny when it satisfies all of the following conditions.

  • It has 3 or 4 vertices.
  • Two consecutive edges share only their common endpoint, and two edges that are not consecutive share no point at all.
  • Both coordinates of every vertex are integers.
  • Every vertex (x,y)(x, y) satisfies 0xxbb0 \le x \le x_{bb} and 0yybb0 \le y \le y_{bb}.
  • At least one vertex has xx-coordinate 00, at least one has xx-coordinate xbbx_{bb}, at least one has yy-coordinate 00, and at least one has yy-coordinate ybby_{bb}.
  • Its area is at most 5000050000.

A skinny polygon does not have to be convex. Several skinny polygons exist for one pair (xbb,ybb)(x_{bb}, y_{bb}), so this problem asks for one of them, fixed as follows.

Let g=gcd(xbb,ybb)g = \gcd(x_{bb}, y_{bb}), p=xbb/gp = x_{bb}/g and q=ybb/gq = y_{bb}/g. Define two quadrilaterals.

  • Q1Q_1: the integer rr with 1rp1 \le r \le p and rq1(modp)rq \equiv 1 \pmod{p} is unique. Using that rr and s=(rq1)/ps = (rq-1)/p, the vertices of Q1Q_1 in order are (0,0)(0, 0), (r,s)(r, s), (xbb,ybb)(x_{bb}, y_{bb}), (pr,qs)(p-r, q-s). The area of Q1Q_1 is gg.
  • Q2Q_2: the vertices of Q2Q_2 in order are (0,0)(0, 0), (xbb,ybb1)(x_{bb}, y_{bb}-1), (p,q)(p, q), (xbb1,ybb)(x_{bb}-1, y_{bb}). The area of Q2Q_2 is (p+q)/2(p+q)/2.

Both Q1Q_1 and Q2Q_2 are skinny. Print Q1Q_1 when 2gp+q2g \le p+q, and Q2Q_2 otherwise. The rule prints the one with the smaller area, and Q1Q_1 when the two areas are equal.

Input

The first line contains the number of test cases nn (1n1051 \le n \le 10^5). Each of the next nn lines holds one test case. A line consists of two integers xbbx_{bb} and ybby_{bb} (2xbb1092 \le x_{bb} \le 10^9, 2ybb1092 \le y_{bb} \le 10^9).

Output

For each test case print the answer in the following format.

4
x1 y1
x2 y2
x3 y3
x4 y4

The first line is the number of vertices, which is always 44. The next four lines give the vertices in the order fixed in the statement, one vertex per line, with the two coordinates separated by a single space.