#include <iostream>
#include <math.h>
#include <cstdio>
#include <vector>


using namespace std;

int main()
{
	freopen("SEGMENT.IN", "r", stdin);
	int x, T, y;
	long double g; 
	long long k, x1, x2, y1, y2;
	scanf("%d", &T);
	for (int poo=0; poo<T; poo++)
	{
		k=0;
		scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
		if (x2-x1==0)
			k=(int)fabs((double)y2-(double)y1)+1;
		else
			if (y2-y1==0)
				k=(int)fabs((double)x2-(double)x1)+1;
			else
			{
				if (x1>x2) swap(x1, x2);
				if (y1>y2) swap(y1, y2);
				if (x2-x1>y2-y1)
					for (x=x1; x<=x2; x++)
					{	
						g=(double)(x2*y2-x1*y1+y2*x-y2*x1-y1*x-y2*x1)/(x2-x1);
						if (g==(int)g)
							k+=1;
					}
				else
					for (y=y1; y<=y2; y++)
					{	
						g=(double)(x2*y-x2*y2-y*x1+y1*x1)/(y1-y2);
						if (g==(int)g)
							k+=1;
					}
			}
			printf("%lld\n", k);
	}


	return 0;
}


/*
2
5 2
4 4 3 1 4
5 3
4 4 3 1 4
*/