
#include<iostream>
#include<fstream>

using namespace std;

int main()
{
	ifstream in("SEGMENT.IN");
	long long x1,x2,x,y1,y2;
	int n;
	in>>n;
	long long y;
	long long a,b;
	long long kol=0;
	double e=0.0001;
	while(n>0) {
		kol=0;
		in>>x1>>y1>>x2>>y2;

		if(x1==x2)
			kol=y2-y1+1;
		else	if(y1==y2)
			kol=x2-x1+1;
		else {
			
			if(y2>y1)
			{for(x=x1;x<=x2;x++) {
				a=((x-x1)*(y2-y1))/(x2-x1);
				y=a+y1;
				if ((y-y1)*(x2-x1)==(x-x1)*(y2-y1))
					if(y>=y1 && y<=y2)
						kol++;
				/*else if(long long(y+e)>long long(y) && (int (y+1))>=y1 && (int (y+1))<=y2)
					kol++;*/
				


			}
			}
			else {for(x=x1;x<=x2;x++) {
				a=((x-x1)*(y2-y1))/(x2-x1);
				y=a+y1;
				if ((y-y1)*(x2-x1)==(x-x1)*(y2-y1))
					if(y>=y2 && y<=y1)
						kol++;
				/*else if(long long(y+e)>long long(y) && (int (y+1))>=y2 && (int (y+1))<=y1)
					kol++;*/
			}
		}
		}
		cout<<kol<<endl;
		n--;}

	return 0;
}