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

int f (int dx,int dy)
{
		int del=dy;
		
		if (dy/dx)

		del--;
		while (del--)
		{
			if(dx%(del+1)==0)
				return (del+1);

		}

		return -1;

}

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

	in>>n;

	while(n--)
	{
		in>>x1>>y1>>x2>>y2;

		dx=(abs(x1-x2));
		dy=(abs(y1-y2));
		
		if (x1==x2==y1==y2)
		{
			cout<<1<<endl;
			continue;
		}
	
		if (dx==0)
		{
			cout<<abs(y1-y2)+1<<endl;
			continue;
		}

		if (dy==0)
		{
			cout<<abs(x1-x2)+1<<endl;
			continue;
		}

		if(dx/dy==1)
		{
			cout<<abs(x1-x2)+1<<endl;
			continue;
		}
		
		if(dy/dx==1)
		{
			cout<<abs(x1-x2)+1<<endl;
			continue;
		}
		
			
			
	

		int  answ;

		if (dx<dy)
		{
			answ=f(dx,dy);

	
		}
		else
		{
			answ=f(dy,dx);
		}

				if (answ==-1)
			{
				cout<<2<<endl;
			}
			else
				cout<<answ+1<<endl;

	}
	
	return 0;
}
		




