#include<iostream>
#include<fstream>
#include<math.h>
#include<cmath>
using namespace std;

float f(int x,float k, float b)
{
	return k*x+b;
}


int main()
{
	ifstream in("SEGMENT.IN");
	int n;
	int x1,y1,x2,y2;
	int x;
	float k,b;

	in>>n;

	while(n--)
	{
		in>>x1>>y1>>x2>>y2;
		
		if(x1==x2)
		{
			cout<<fabs((float)(y1-y2))+1<<endl;
			continue;
		}
		
		if(y1==y2)
		{
			cout<<fabs((float)(x1-x2))+1<<endl;
			continue;
		}

		k=(x1-x2)/(y1-y2);
		b=y1-k*x1;

		if(x1>x2)
		{
			int temp;
			temp=x1;
			x1=x2;
			x2=temp;

			temp=y1;
			y1=y2;
			y2=temp;
		}

		int t,count=0;
		for(int x=x1;x<x2;x++)
		{
			t=f(x,k,b);
			if(t == (int)(t))
				count++;
		}

		cout<<count+1<<endl;

		
	}
	
	return 0;
}
		




