program Project1;

{$APPTYPE CONSOLE}

type
   TArr= array of integer;
   TArray = array of TArr;
   TLongNumber = array of Word;

var
   x1,y1,x2,y2:Longint;
   k,b:extended;
   i,j:cardinal;
   sum:cardinal;
   T:Word;
   f:textfile;
procedure InputNumber(const st:string; out ar:TLongNumber);
var
   i,k:word;
   er:integer;
begin
   k:=Length(st) div 3;
   if Length(st) mod 3>0 then Inc(k);
   SetLength(ar,k);
   if k>1 then
      for i:=1 to k-1 do
         Val(copy(st,Length(st)-i*3+1,3),ar[i-1],er);
   Val(copy(st,1,Length(st)-(k-1)*3),ar[high(ar)],er);
end;

procedure OutputNumber(const ar:TLongNumber; out st:string);
var
   s:string;
   i,k:word;
begin
   st:='';
   for i:=0 to high(ar) do
   begin
      Str(ar[i],s);
      if Length(s)<3 then
         for k:=1 to 3-Length(s) do
            s:='0'+s;
      st:=s+st;
   end;
   for i:=1 to Length(st) do
      if st[i]<>'0' then
      begin
         if i=1 then break;
         st:=copy(st,i,Length(st));
         break;
      end;
end;

procedure Addition(var Ar1,Ar2:TLongNumber; out Res:TLongNumber);
var
   i,k,d:word;
begin
   if Length(Ar1)>=Length(Ar2) then
      k:=Length(Ar1)
   else
      k:=Length(Ar2);
   if Length(Ar1)<k then SetLength(ar1,k);
   if Length(Ar2)<k then SetLength(ar2,k);
   d:=0;
   SetLength(Res,k);
   for i:=0 to k-1 do
   begin
      Res[i]:=ar1[i]+ar2[i]+d;
      d:=res[i] div 1000;
      res[i]:=res[i] mod 1000;
   end;
   if d>0 then
   begin
      if Length(res)<k+1 then
         SetLength(res,Length(res)+1);
      res[k]:=res[k]+d;
   end;
end;

procedure Multiplication(var Ar1,Ar2:TLongNumber; out res:TLongNumber);
var
   d,i,k:word;
   c:cardinal;
begin
   SetLength(res,High(ar1)+High(ar2)+1);
   d:=0;
   for i:=0 to high(ar1) do
   begin
      for k:=0 to high(ar2) do
      begin
         c:=ar1[i]*ar2[k];
         res[i+k]:=res[i+k]+c mod 1000 + d;
         d:=c div 1000 + res[i+k] div 1000;
         res[i+k]:=res[i+k] mod 1000;
      end;
      if d>0 then
      begin
         if Length(res)<i+high(ar2)+2 then
            SetLength(res,Length(res)+1);
         res[i+high(ar2)+1]:=res[i+high(ar2)+1]+d;
      end;
   end;
end;

function Y(x:cardinal):Extended;
begin
   Result:=k*x+b;
end;

begin
   AssignFile(f,'SEGMENT.IN');
   Reset(f);
   readln(f,T);
   for j:=1 to T do
   begin
      readln(f,x1,y1,x2,y2);
      if (x1<>x2) and (y1<>y2) then
      begin
         k:=(y1-y2)/(x1-x2);
         b:=y1-k*x1;
         sum:=0;
         if x2>x1 then
            for i:=x1 to x2 do
            begin
               if Frac(Y(i))=0 then Inc(sum);
            end
         else
            for i:=x2 to x1 do
            begin
               if Frac(Y(i))=0 then Inc(sum);
            end;
      end else
      if x1=x2 then
         sum:=abs(y2-y1)+1 else
      if y1=y2 then
         sum:=abs(x2-x1)+1;
      writeln(sum);
   end;
   close(f);
end.
