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<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int gcd(int x,int y){
	if(x < y){

		swap(x,y);
	}

	if(y == 0){
		return x;
	}else{
		return gcd(y,x%y);
	}
}


int extend_Euclid(int a,int b,int& ans_x,int& ans_y){
	if(b == 0){ //再帰の一番最後にたどり着いた場合
		ans_x = 1;
		ans_y = 0;
		return a; //最小公倍数
	}else{
		int ret = extend_Euclid(b,(a%b),ans_y,ans_x);
		ans_y -= (a/b)*ans_x;
		return ret;
	}
}

//https://icpc.iisf.or.jp/past-icpc/comments/2016-slides.pdf

void func(){

	int x_bb,y_bb;

	scanf("%d %d",&x_bb,&y_bb);

	int x,y,num;

	num = extend_Euclid(x_bb,y_bb,x,y);

	if(num <= 50000){

		printf("3\n");
		printf("0 0\n");

		printf("%d %d\n",x_bb,y_bb);

		printf("%d %d\n",abs(y),abs(x));

	}else{

		printf("4\n");
		printf("0 0\n");

		printf("%d %d\n",x_bb-1,y_bb);
		printf("%d %d\n",x_bb/num,y_bb/num);
		printf("%d %d\n",x_bb,y_bb-1);
	}
}

int main(){

	int num_case;

	scanf("%d",&num_case);

	for(int loop = 0; loop < num_case; loop++){

		func();
	}

	return 0;
}