Find C

Given lattice points A and B, list K lattice points C such that both segments AC and BC are primitive and triangle ABC contains no other lattice point.

Hard8Number theoryGeometryMathBrute forceNo attempts yetTime limit1sMemory limit512 MB

Problem

Two friends stand at AA and BB, two distinct lattice points in the plane. To fit both of them in one photo you pick a lattice point CC that satisfies all of the following.

  1. CC differs from AA and from BB.
  2. Segment ACAC contains no lattice point other than its two endpoints.
  3. Segment BCBC contains no lattice point other than its two endpoints.
  4. Triangle ABCABC has area greater than 00, so CC does not lie on the line through AA and BB.
  5. No lattice point lies strictly inside triangle ABCABC.

A point whose xx coordinate and yy coordinate are both integers is a lattice point.

Nobody takes a single snap, so for the given AA and BB you need KK such points CC. Infinitely many points satisfy the conditions, so the output section fixes which KK of them you print.

Input

The first line contains the number of test cases TT. (1T10001 \le T \le 1000)

Each of the next TT lines contains five integers AxA_x, AyA_y, BxB_x, ByB_y, KK. The two points A=(Ax,Ay)A = (A_x, A_y) and B=(Bx,By)B = (B_x, B_y) are distinct. (109Ax,Ay,Bx,By109-10^9 \le A_x, A_y, B_x, B_y \le 10^9, 0K0 \le K, the sum of all KK is at most 2000020000)

Output

For each test case print KK lines, each holding the coordinates of one point CC in the format "CxC_x CyC_y". A test case with K=0K = 0 prints nothing.

Choose the KK points this way. Among the lattice points CC that satisfy every condition above, keep only those with

s(C)=(BxAx)(CyAy)(ByAy)(CxAx)>0s(C) = (B_x - A_x)(C_y - A_y) - (B_y - A_y)(C_x - A_x) > 0

and

f(C)=(CxAx)(BxAx)+(CyAy)(ByAy)0.f(C) = (C_x - A_x)(B_x - A_x) + (C_y - A_y)(B_y - A_y) \ge 0.

Print KK of the kept points in increasing order of f(C)f(C), starting from the smallest.

Infinitely many points remain, so KK of them always exist, and the kept points have pairwise different values of f(C)f(C), so the output is unique. Every coordinate chosen by this rule has absolute value at most 101410^{14}.