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 MBTwo integers xbb and ybb are given. Call a polygon skinny when it satisfies all of the following conditions.
A skinny polygon does not have to be convex. Several skinny polygons exist for one pair (xbb,ybb), so this problem asks for one of them, fixed as follows.
Let g=gcd(xbb,ybb), p=xbb/g and q=ybb/g. Define two quadrilaterals.
Both Q1 and Q2 are skinny. Print Q1 when 2g≤p+q, and Q2 otherwise. The rule prints the one with the smaller area, and Q1 when the two areas are equal.
The first line contains the number of test cases n (1≤n≤105). Each of the next n lines holds one test case. A line consists of two integers xbb and ybb (2≤xbb≤109, 2≤ybb≤109).
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 4. 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.