#include <iostream>
#include <cmath>
#include <vector>
#define EPS 0.000000001
using namespace std;

__int64 gcd (__int64 a, __int64 b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}
inline int myround(double x) {
	bool sign = false;
	if (x < 0) {
		sign = true;
	}
	x = ceil(fabs(x));
	if (sign) {
		x = -x;
	}
	return x;
}
int main()
{

	freopen("SEGMENT.IN", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int x1, y1, x2, y2, count = 0; 
		cin >> x1 >> y1 >> x2 >> y2;
		if (y1 == y2) {
			cout << abs(x2 - x1) + 1 << endl;
			continue;
		}
		if (x1 == x2) {
			cout << abs(y2 - y1) + 1 << endl;
			continue;
		}
		cout << gcd(abs(x2- x1), abs(y2 -y1)) + 1 <<endl;
		continue;

	}
	return 0;
}