program Project1;

{$APPTYPE CONSOLE}

var
   x1,y1,x2,y2:Longint;
   k,b:extended;
   j:word;
   i:longint;
   sum:cardinal;
   T:Word;
   f:textfile;

function Y(x:longint):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);
      sum:=0;
      if (x1<>x2) and (y1<>y2) then
      begin
         k:=(y1-y2)/(x1-x2);
         b:=y1-k*x1;
         if x2>x1 then
         begin
            i:=x1;
            repeat
               if Frac(Y(i))=0 then Inc(sum);
               i:=i+1;
            until i=x2+1;
         end
         else
         begin
            i:=x2;
            repeat
               if Frac(Y(i))=0 then Inc(sum);
               i:=i+1;
            until i=x1+1;
         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.
