#include <stdio.h>
#include <iostream>
#include <math.h>
#include <conio.h>

int main()
{
	long t,n,a,b,x1,y1,x2,y2,cash, k = 0;
	freopen("SEGMENT.IN", "r", stdin);
	scanf("%ld", &n);
	for (long i = 0; i<n; ++i)
	{
		k = 0;
		scanf("%ld %ld %ld %ld", &x1,&y1,&x2,&y2);
		if (x1 > x2)
		{
				cash = x1;
				x1 = x2;
				x2 = cash;
		}
		if (y1 > y2)
		{
				cash = y1;
				y1 = y2;
				y2 = cash;
		}

		if (x1 != x2) 
		{
			double con = (double) (y1 - y2)/(double)(x1 - x2);
			for (long x = x1+1; x < x2; ++x)
			{
				double y = (double) con * (double) ((double)x - (double) x2) + (double)y2;
				if (y == (long)y) 
					++k;
			}
		}
		else
			k=y2-y1-1;
		
		printf("%ld\n", k+2);
	}
	printf("1234");
	return 0;
}
