#include <iostream>
#include <fstream>
#include <math.h>

using namespace std;

void main()
{
float k,b,t1,t2,u;
int n,x1,y1,x2,y2,d,l,toch,ut;
fstream F;
F.open("SEGMENT.IN");
F>>n;
while(n!=0)
{
toch=0;
F>>x1;
F>>y1;
F>>x2;
F>>y2;
t1=(y2-y1);
t2=(x2-x1);
if(t2!=0)
{
k=t1/t2;
b=y1-k*x1;
if(x1!=x2)
{
if(x1<x2)
{d=x1;
l=x2;}
else
	{d=x2;
l=x1;}
for(int i=d; i<=l; i++)
{
u=k*i+b;
ut=int(u);
if(ut==u)
toch++;}
cout<<toch<<endl;
/**/
}
else
{
if(y1<y2)
{d=y1;
l=y2;}
else
	{d=y2;
l=y1;}
for(int i=d; i<=l; i++)
{
u=k*i+b;
ut=int(u);
if(ut==u)
toch++;}
cout<<toch<<endl<<endl<<endl;
}
}
else 
cout<<abs(y1-y2)+1;
n--;
}

}