#include <iostream>
#include <fstream>
using namespace std;

long nod(long a,long b)
{
	long c;
	if (a<b)
	{		
		c=a;		a=b;
		b=c;
	}
	
	while(b!=0)
	{
		a=a%b;		
		if (a<b)
		{
			c=a;	a=b;
			b=c;
		}
	}
	return a;
}


void main()
{
	ifstream f("SEGMENT.IN",ios::in);	
	int T;
	f>>T;
	int x1,x2,y1,y2;
	for (int i=0; i<T; i++)
	{		
		f>>x1>>y1>>x2>>y2;
		x2-=x1;
		y2-=y1;
		cout<<nod(x2,y2)+1<<endl;		
	}	
	f.close();
}

