#include <cstdio>
#include <algorithm>
using namespace std;

int gcd (int a, int b) {
	while (b) {
		a %= b;
		swap (a, b);
	}
	return a;
}

int main()
{
	freopen("segment.in", "r", stdin);

	int a, b, c, d, tests;

	scanf("%d", &tests);

	while(tests > 0)
	{
		scanf("%d%d%d%d", &a, &b, &c, &d);
		printf("%d\n", gcd(max(a, c) - min(a, c), max(b, d) -  min(b, d)) + 1);

		tests--;
	}

	return 0;
}