
#include<iostream>
#include<fstream>

using namespace std;

int main()
{
	ifstream in("SEGMENT.IN");
	long long x1,x2,x,y1,y2;
	int n;
	in>>n;
	double y;
	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=(y2-y1)/(double)(x2-x1);
			b=(x1*y2-x1*y1-y1*x2+y1*x1)/(double)(x2-x1);
			if(y2>y1)
			{for(x=x1+1;x<x2;x++) {
				y=x*a-b;
				if(long long(y)==y && y>=y1 && y<=y2)
					kol++;
			}
			}
			else {for(x=x1+1;x<x2;x++) {
				y=x*a-b;
				if(long long(y)==y && y>=y2 && y<=y1)
					kol++;
			}
		}
		}
		cout<<kol<<endl;
		n--;}

	return 0;
}