#include <iostream>
#define MOD(a) ((a)>0 ? (a) : -(a))
#define MIN(a,b) ((a)>(b) ? (b) : (a))
using namespace std;

int gcd(int a, int b)
{
	if(a%b == 0)
		return b;
	else
		return gcd(b, a%b);
}


int main()
{
	freopen("segment.in","r",stdin);
	int N,x1,x2,y1,y2,px,py,res=0;
	cin >> N;
	for(int i = 0; i < N; i++)
	{
		cin >> x1 >> y1 >> x2 >> y2;
		px=MOD((x1-x2));
		py=MOD((y1-y2));
		if(px == 0)
		{
			cout << py+1 << endl;
		}
		else if(py == 0)
		{
			cout << px+1 << endl;
		}
		else
			cout << gcd(px,py)+1 << endl;
	}
	return 0;
}