Problem: Example

Input

2
5 6
1000000000 2


Output

4
5 6
0 6
0 0
5 0
3
1000000000 0
0 2
999999999 0

Solution (in CPP):

Solution:
//(????????°, ?????¨????????????????????°)??§??´?????????????????¨, ???????????¢????????????????????????????????????????????§??????
//????????¨, ????????????????????????3?§???¢??¨4?§???¢????????????????????????
//A * B ??? 25000^2 ??? min(A, B) ??? 25000???????????¢???????°??????????????????????????????¨??£?§£???????????¨?????????????????????

#include <iostream>
#include <vector>
#define int long long
using namespace std;

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ax + by = gcd(a, b)??¨????????´??°???(x, y)??????????±?????????????.
void extgcd(int a, int b, int &x, int &y) {
	int r[100];
	int q[100];
	int cnt;
	
	r[0] = a;
	r[1] = b;
	cnt = 2;
	while (r[cnt - 2] % r[cnt - 1] != 0) {
		q[cnt - 1] = r[cnt - 2] / r[cnt - 1];
		r[cnt] = r[cnt - 2] - q[cnt - 1] * r[cnt - 1];
		cnt++;
	}
	q[cnt - 1] =r[cnt - 2] /  r[cnt - 1];
	
	x = 0;
	y = 1;
	for (int i = 0; i < cnt - 2; i++) {
		int nx = y;
		int ny = x - y * q[cnt - 2 - i];
		x = nx;
		y = ny;
	}
}

signed main() {
	int n, w, h;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> w >> h;
		int g = gcd(w, h);
		if (g < (w + h) / (2 * g)) {
			int x, y;
			extgcd(w, -h, y, x);
			if (x < 0) { x *= -1; y *= -1; }
			cout << 3 << endl;
			cout << 0 << " " << 0 << endl;
			cout << w << " " << h << endl;
			cout << x << " " << y << endl;
		}
		else {
			cout << 4 << endl;
			cout << 0 << " " << 0 << endl;
			cout << w << " " << h - 1 << endl;
			cout << w / g << " " << h / g << endl;
			cout << w - 1 << " " << h << endl;
		}
	}
	return 0;
}