#include <iostream>
#include <fstream>
using namespace std;

void main()
{
	int t,ii,y1,y2,x1,x2,s,n,i;
	double b,k,y;
	ifstream in("SEGMENT.IN");
	in>>t;
	for(ii=0;ii<t;ii++){
		s=0;
		in>>x1>>y1>>x2>>y2;
		if(x2-x1==0) s=abs(y1-y2)+1; else
		{k=(y2-y1)/(x2-x1); b=y1-k*x1; 
		if((x2-x1<0)){ x1+=x2; x2=x1-x2; x1=x1-x2;}
		n=x2-x1+1; 
		for(i=0;i<n;i++){
			y=k*x1+b;
			y1=y;
			if(y-y1==0)s++;
			x1++;
		}
		}
		cout<<s<<endl;
	}
	//system("pause");
}