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:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll gcd(ll a, ll b) {
	if(a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}
//x,yがax+by=gcd(a,b)の解になる
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}
int main(){
	int n; cin >> n;
	ll key = (ll)25000 * 25000 * 2;
	rep(aa, n) {
		ll a, b; cin >> a >> b;
		ll x, y;
		bool tra = false;
		if (a < b) {
			tra = true; swap(a, b);
		}
		ll d = gcd(a, b);
		if (d == 1) {
			extgcd(b, -a, x, y);
			if (tra) {
				swap(a, b); swap(x, y);
			}
			cout << 3 << endl;
			cout << "0 0" << endl;
			cout << a << " " << b << endl;
			cout << x << " " << y << endl;
		}
		else {
			ll a1 = a / d; ll b1 = b / d;
			if (a1*a1 + b1 * b1 <= key) {
				if (tra) {
					swap(a1, b1); swap(a, b);
				}
				cout << 4 << endl;
				cout << "0 0" << endl;
				cout << a - 1 << " " << b << endl;
				cout << a1 << " " << b1 << endl;
				cout << a << " " << b - 1 << endl;
			}
			else {
				extgcd(b1, -a1, x, y);
				if (tra) {
					swap(x, y); swap(a, b);
				}
				cout << 3 << endl;
				cout << "0 0" << endl;
				cout << a << " " << b << endl;
				cout << x << " " << y << endl;
			}
		}
	}
	return 0;
}