#include <iostream>
#include <deque>
#include <math.h>
using namespace std;

int main(){
	freopen ("SEGMENT.IN","r",stdin);

	int am_tests;
	cin>>am_tests;

	for (int test=0;test<am_tests;test++)
	{
		
		__int64 x=0,y=0,x2=0,y2=0;

		__int64 A[1000];
		__int64 B[1000];
		cin >>x>>y>>x2>>y2;
		A[0]=x;
		A[1]=y;
		A[2]=x2;
		A[3]=y2;


	


		for (int i = 0; i<4; i++){
			if (A[i] < 0) {A[i]*=-1;};
		}
		__int64 max=A[0];
		__int64 min=A[0];
		for(int i=0;i<4;i++)
		{
			if(max<A[i])
				max=A[i];
				if(min>A[i])
				min=A[i];
		}
	

		

		__int64 kol1=0,kol2=0;
		if(A[1]==A[3])
		{
			kol1=A[0]-A[2];
			if(kol1<0)
			{
				kol1=kol1*-1;
				kol1=kol1+1;
				cout<<kol1;
				return 0;
			}
			kol1=kol1+1;
			cout<<kol1;
			return 0;
		}
		if(A[0]==A[2])
		{
			kol2=A[1]-A[3];
			if(kol2<0)
			{
				kol2=kol2*-1;
				kol2=kol2+1;
				cout<<kol2;
				return 0;
			}
			kol2=kol2+1;
			cout<<kol2;
			return 0;
		}



		double k;
		if (x2 != 0){
			k=y2/x2;
		}
		else k = 1;

		__int64 fl=0;
		for(__int64 i=min;i<=max;i++)
		{
			for(__int64 j=min;j<=max+1;j++)
			{
				if(i==k*j)
				{
					fl++;
					min = j;
					break;
					
				}
			}
		}

		cout<<fl << endl;
	}
	return 0;
}