# include <fstream>
# include <iostream>
# include <string>
# include <vector>
# include <math.h>
using namespace std;

void main ()
{
	int i,j,T;
	ifstream in("SEGMENT.IN");
    in>>T;
	for(int i=0; i<T; i++)
	{	
		double y;
		int ans=0;
		int x1,y1,x2,y2;
		in>>x1>>y1>>x2>>y2;
		if(x1!=x2){
			if(x1>x2){
				swap(x1,x2);
				swap(y1,y2);
			}
			for(j=x1;j<=x2;j++){
				double X1=x1,X2=x2,Y1=y1,Y2=y2,J=j;
				y=(J-X1)*(Y2-Y1)/(X2-X1)+Y1;
				if(fabs(y-(int)y)<0.00000001)
					ans++;
			}
		}
		else{
			if(y1>y2){
				swap(x1,x2);
				swap(y1,y2);
			}
			ans=y2-y1+1;
		}
		cout<<ans<<endl;
	}
	//system("pause");
}
