import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: student
 * Date: 10.11.13
 * Time: 10:21
 * To change this template use File | Settings | File Templates.
 */
public class H {

    public static int NOD(int x, int y) {
        int a = Math.max(x, y);
        int b = Math.min(x, y);

        if (a == b || b == 0) return a;
        else return NOD(b, a%b);
    }

    public static void main(String[] args) throws FileNotFoundException {
        Scanner scanner = new Scanner(new File("SEGMENT.IN"));

        int T = scanner.nextInt();

        for (int i = 0; i < T; i++) {
            int x1 = scanner.nextInt();
            int y1 = scanner.nextInt();
            int x2 = scanner.nextInt();
            int y2 = scanner.nextInt();

            int c = NOD(Math.abs(x1-x2), Math.abs(y1-y2));
            System.out.println(c+1);
        }
    }

}
