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


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;
		}
		if (y1 > y2) {
			int tmp = y1;
			y1 = y2;
			y2 = tmp;
		}
		for (int y = y1; y <= y2; ++y) {
			
			double x = (-(double)y * (x2 - x1) +  y1 * x2 - y2 * x1) / (y1 - y2);
			if (fabs(x - (int)x)< EPS)
				count++;
		}
		cout << count << endl;
	}
	return 0;
}