var x1,x2,y1,y2,n,i,l1,l2:longint;
f1:text;
begin
assign(f1,'SEGMENT.IN');
reset(f1);
readln(f1,n);
for i:= 1 to n do begin
readln(f1,x1,y1,x2,y2);
l1:=abs(x1-x2);
l2:=abs(y1-y2);
while (l1<>l2) and (l1>0) and (l2>0) do begin
if l1>l2 then l1:=l1 mod l2 else l2 := l2 mod l1;
end;
if l1 > 0 then writeln(l1+1) else writeln(l2+1);
end;
close(f1);
end.