var t: text;
i,n : integer;
x1,y1,x2,y2,c1,c2: int64;

function euclide(a,b : int64) : int64;
        var res : int64;
         begin
                if (b = 0) then res := a else
                        if (a = 0) then res := b else
                if (a > b) then res := euclide(a mod b, b) else
                res := euclide(b mod a, a);
                euclide := res;

         end;
begin
        assign(t,'segment.in');
        reset(t);
        readln(t,n);

        for i := 1 to n do begin
                readln(t,x1,y1,x2,y2);
                c1 := abs(x1-x2);
                c2 := abs(y1-y2);

                writeln(euclide(c1,c2)+1);
        end;
        close(t);
end.
