eolymp
bolt
Try our new interface for solving problems
Problems

Hard Cuts

Hard Cuts

Given a rectangle with integer side lengths, your task is to cut it into the smallest possible number of squares with integer side lengths.

Input

The first line contains a single integer t (1t3600) - the number of test cases. Each of the next t lines contains two integers wi, hi - the dimensions of the rectangle (1wi, hi60, for any ij, either wiwj or hihj).

Output

For the i-th test case, output ki - the minimal number of squares, such that it is possible to cut the wi by hi rectangle into ki squares. The following ki lines should contain three integers each: xij , yij - the coordinates of the bottom-left corner of the j-th square and lij - its side length (0xijwi - lij, 0yijhi - lij). The bottom-left corner of the rectangle has coordinates (0, 0) and the top-right corner has coordinates (wi, hi).

prb9440.gif

Time limit 1 second
Memory limit 128 MiB
Input example #1
3
5 3
5 6
4 4
Output example #1
4
0 0 3
3 0 2
3 2 1
4 2 1
5
0 0 3
0 3 3
3 0 2
3 2 2
3 4 2
1
0 0 4
Source 2016 ACM NEERC, Northern region, October 22, Problem H