#include <iostream>
#include <cmath>

using namespace std;

int ab(int a)
{
	if (a < 0)
		return -a;
	return a;
}

int main()
{
	freopen("SEGMENT.IN","r",stdin);
	//freopen("output.txt","w",stdout);

	int t,x1,x2,y1,y2,m;
	cin >> t;
	for (int i=0;i<t;i++)
	{
		cin >> x1 >> y1 >> x2 >> y2;
		if (x2 == x1)
		{
			cout << ab(y2-y1) + 1 << endl;
			continue;
		}
		if (y2 == y1)
		{
			cout << ab(x2-x1) + 1 << endl;
			continue;
		}
		
		
		x2 += -x1;
		x1 += -x1;
		int a = (x1 < x2)?x1:x2;
		int b = (x1 > x2)?x1:x2;
		double k = ((y2-y1)*1.0 / (x2-x1));
		int sum = 0;
		for (int j=a;j<=b;j++)
		{
			if (k*j - floor(k*j) < 0.000000001)
			{
				sum++;
			}
		}
		cout << sum << "\n";
	}
}