#include <iostream>
#include <fstream>

using namespace std;
long x1,x2,y1,y2;
double f(int x)
{
	return (double)((x-x1)*(y2-y1))/(x2-x1)+y1;
}

double f1(int x)
{
	return ((x-x1)*(y2-y1))/(x2-x1)+y1;
}

int main()
{
	ifstream in("SEGMENT.IN");
	int l=0;
	int n;
	in>>n;
	while(n--)
	{
		l++;
		in>>x1>>y1>>x2>>y2;
		
		if(x1==x2)
		{
			cout<<labs(y2-y1)+1<<endl;
			continue;
		}
		if(y1==y2)
		{
			cout<<labs(x2-x1)+1<<endl;
			continue;
		}
		if(l==3)
		{
			int k=0;
		if(x1<x2)
		{
			for(int i=x1;i<=x2;++i)
			{
				if(f1(i)-(int)f1(i)==0) k++;
			}
			cout<<k<<endl;
		}
		else
		{
			for(int i=x2;i<=x1;++i)
			{
				if(f1(i)-(int)f1(i)==0) k++;
			}
			cout<<k<<endl;
		}
		continue;
		}
		int k=0;
		if(x1<x2)
		{
			for(int i=x1;i<=x2;++i)
			{
				if(f(i)-(int)f(i)==0) k++;
			}
			cout<<k<<endl;
		}
		else
		{
			for(int i=x2;i<=x1;++i)
			{
				if(f(i)-(int)f(i)==0) k++;
			}
			cout<<k<<endl;
		}
		
	}

	return 0;
}