#include<time.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
double random()
{return (double)rand()/RAND_MAX;}
int random(int m)
{
return (int)(random()*(m-1)+0.5);
}
int n,m;
void in(int &a)
{
char ch;
while((ch=getchar())<'0'||ch>'9');
for(a=0;ch>='0'&&ch<='9';ch=getchar()) a=a*10+ch-'0';
}
int main()
{
srand(time(NULL));
int T;
in(T);
freopen("1.txt","w",stdout);
printf("%d
",T);
while(T--)
{
in(m),in(n);
printf("%d
",m);
for(int i=0;i!=m;++i)//m ,n 。
{
int x;
int y;
bool flag=false;
if(rand()%2) flag=true;
while(1)
{
x=random(n)+1;
y=random(n)+1;
if(x!=y&&x&&y) break;
}
if(i%2==1&&flag) x=-x,y=-y;
else if(i%2==1&&!flag) x=-x;
else if(i%2==0&&flag) y=-y;
printf("%d %d
",x,y);
}
}return 0;
}