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

using namespace std;

struct point
{
	int x,y;
};

int main()
{
	ifstream in("SEGMENT.IN");
	int 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);
				else
				{
					if (p1.y>p2.y) swap(p1,p2);
				}
				double k=double(p2.x-p1.x)/double(p2.y-p1.y);
				int r=0;
				for (int h=p1.x;h<=p2.x;h++)
				{
					double y=k*(h-p1.y)+p1.y;
					if(int(y)==y) r++;
				}
				cout<<r<<endl;
			}
		}
	}
	return 0;
}