#include <iostream>
//#include "windows.h"
#include <algorithm>
using namespace std;

int gcd(int a, int b) {
	while(a > 0) {
		a^=b^=a^=b%=a;
	}
	return b;
}

int main() {
	int n, a, b, c, d;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin  >> a >> b >> c >> d;
		if(a == c && b ==d) {
			cout << 1 << endl;
		}
		else if(a == c) {
			cout << abs(b-d)+1 << endl;
		}
		else if(b == d) {
			cout << abs(a-c)+1 << endl;
		}
		else {
			cout << gcd(abs(a-c), abs(b-d))+1 << endl;
		}
	}

	//system("pause");
	return 0;
}