
#include<iostream>
#include<fstream>

using namespace std;

int main()
{
	ifstream in("SEGMENT.IN");
	long long x1,x2,x,y,y1,y2;
	int n;
	in>>n;
	long long kol=0;
	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 {
			for(x=x1;x<=x2;x++)
				for(y=y1;y<=y2;y++)
				{
					if(x*y2-x*y1-x1*y2+x1*y1 == y*x2-y*x1-y1*x2+y1*x1)
					{kol++;break;}
					else if(x*y2-x*y1-x1*y2+x1*y1 < y*x2-y*x1-y1*x2+y1*x1)
						break;
				}

		}
		cout<<kol<<endl;
		n--;}

	return 0;
}