
#include<iostream>
#include<fstream>

using namespace std;

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

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

	return 0;
}