#include <iostream>
#include <fstream>
#include <string>
#include <map>

using namespace std;

struct point
{
	__int64 x,y;
};

int main()
{
	ifstream in("SEGMENT.IN");
	__int64 t;
	in>>t;
	for (int i=0;i<t;i++)
	{
		point p1,p2;
		in>>p1.x>>p1.y>>p2.x>>p2.y;

		if (p1.y==p2.y)
		{
			cout<<abs(p1.x-p2.x)+1<<endl;
		}
		else
		{
			if (p1.x==p2.x)
			{
				cout<<abs(p1.y-p2.y)+1<<endl;
			}
			else
			{
				if (p1.x>p2.x) swap(p1,p2);
				p2.x-=p1.x;p2.y-=p1.y;
				if (p2.y<0) p2.y*=-1;
				__int64 r=0;
				for (__int64 h=0;h<=p2.x;h++)
				{
					
					if((p2.y*h)%p2.x==0) r++;
				}
				cout<<r<<endl;
			}
		}
	}
	return 0;
}