# include <iostream>
# include <vector>
# include <cstdio>
# include <algorithm>
# include <cmath>
# include <set>
using namespace std;
const double eps=1e-9;
struct pt{
	double x, y;
	pt(){}
	pt(double x, double y):x(x), y(y){}
	void scan(){
		cin>>x>>y;
	}
};
struct line{
	double a, b, c;
	line(){}
	line(pt A, pt B){
		a=B.y-A.y;
		b=A.x-B.x;
		c=B.x*A.y-A.x*B.y;
	}
};
set<pair<int, int > > g;
void online(line l, double x){
	double y=-(l.a*x+l.c)/l.b;
	if(int(y)-y < eps )
		if(y>=0)
			g.insert(make_pair(x, y+eps));
		else
			g.insert(make_pair(x, y-eps));
}
void online2(line l, double y){
	double x=-(l.b*y+l.c)/l.a;

	if(int(x)-x < eps)
		if(x>=0)
			g.insert(make_pair(x+eps, y));
		else
			g.insert(make_pair(x-eps, y));
}

int main(){
	freopen("SEGMENT.IN", "r", stdin);
	int T;
	cin>>T;
	while(T--){
		pt p, q;
		p.scan(), q.scan();
		if(p.x>q.x) swap(p, q);
		line l(p, q);
		int kol=0;
		for(int i=p.x; i<=q.x; i++){
			online(l, i);
		}
		if(p.y>q.y) swap(p, q);
		for(int i=p.y; i<=q.y; i++){
			online2(l, i);
		}
		
		cout<<g.size()<<endl;
		g.clear();
	}
}
/*
2
0 0 3 3
3 6 3 5
*/