// problem_H.cpp: определяет точку входа для консольного приложения.
//

#include "stdafx.h"
#include "stdio.h"
#include <iostream>
#include "math.h"

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
	int a1,b1,x1,j,y1,x2,y2,t,i,y,tochki,shag;
	double k,b,yz;
	FILE *F;
	F=fopen("SEGMENT.IN","r");
	fscanf(F,"%d",&t);
	
	for (i=1;i<=t;i++)
	{
	//cin>>x1>>y1>>x2>>y2;
	fscanf(F,"%d%d%d%d",&x1,&y1,&x2,&y2);
    if (x2-x1==0) k=1; else 	k=(double(y2-y1))/(x2-x1);
	b=float(y2-k*x2);
	//if (x1<x2) {a1=x1; b1=x2;} else {a1=x2; b1=x1;};
	//if (x1==x2) if (y1<y2) {a1=y1; b1=y2;} else {a1=y2; b1=y1;};
	tochki=0;
	if ((x1!=x2)&&(y1!=y2))
	{
	for (j=1;j<=10000000;j++)
		if (int(j*k)-(j*k)==0) {shag=j;break;}
	// if (x2>x1){cout<<((abs(x2-x1))/shag+1);} else {cout<<((abs(x1-x2))/shag+1);};

	// if (  int(   abs(x2-x1)/shag    )-(abs(x2-x1)/shag) >0   ) cout<<"+1";
	tochki=0;
	 for (j=x1;j<=x2;j+=shag) 
      	 {
		 if (int(k*j+b)-(k*j+b)==0) tochki++;
	     }
		 cout<<tochki;

	}
	else
	{if (y1==y2){ if (x2>x1){cout<<abs(x2-x1)+1;} else {cout<<abs(x1-x2)+1;}};
	if (x1==x2) { if (y2>y1){cout<<abs(y2-y1)+1;} else {cout<<abs(y1-y2)+1;}}; 

	}
	cout<<"\n";
	}
	

	fclose(F);
	//getchar();
	//getchar();
	return 0;
}

