#include<iostream>
using namespace std;
float x,y,a,b,c,d,j,t,k,l,m=1;

int main()
{
	freopen("SEGMENT.in", "rt",stdin);
	cin>>t;
	for(l=0;l<t;l++)
	{
	m=1;
	cin>>x>>y>>d>>c;


	if(x==d)
	{if(y<c) 
	m=c-y+1;
	else
	m=y-c+1;}
	a=(y-c)/(x-d);
	b=y-a*x;
	
	for(j=x;j<d;j++)
	{
	k=a*j+b;
	if(k-(int)k==0)
	m++;
	}

	cout<<m<<endl;
	}
	return 0;
}
