import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args)throws IOException{
		InputStream inputStream;
		OutputStream outputStream;
		
		inputStream = new FileInputStream("segment.in");
		outputStream = System.out;
		
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
	
		int t = in.nextInt();
		for(int test=0; test<t; ++test){
			long x1 = in.nextLong();
			long y1 = in.nextLong();
			long x2 = in.nextLong();
			long y2 = in.nextLong();
			
			long s1 = Math.abs(x2-x1);
			long s2 = Math.abs(y2-y1);
			
			long g = gcd(s1,s2);
			out.writeln(g+1);
		
		}
		
		out.flush();
		out.close();
	
	}
		
	
	
	static long gcd(long a, long b){
		return b==0 ? a : gcd(b,a%b);
	}
}

class InputReader{
	
	public InputReader(InputStream stream){
		reader = new BufferedReader(new InputStreamReader(stream));
		tokenizer=null;
	}
	
	public String next(){
		while(tokenizer==null || !tokenizer.hasMoreTokens()){
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		
		return tokenizer.nextToken();
	}
	
	public String nextLine(){
		tokenizer=null;
		try {
			return reader.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	
	public int nextInt(){
		return Integer.parseInt(next());
	}
	
	public long nextLong(){
		return Long.parseLong(next());
	}
	
	public double nextDouble(){
		return Double.parseDouble(next());
	}
	
	public int[] nextIntArr(int n){
		int[] rez = new int[n];
		for(int i=0; i<n; ++i)
			rez[i]=nextInt();
		
		return rez;
	}
	
	private BufferedReader reader;
	private StringTokenizer tokenizer;
}

class OutputWriter{
	
	public OutputWriter(Writer out){
		this.out = new PrintWriter(out);
	}
	
	public OutputWriter(OutputStream out){
		this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
	}
	
	public void write(Object ...o){
		for(Object cur : o)
			out.print(cur);
		
	}
	
	public void writeln(Object ...o){
		write(o);
		out.println();
	}
	
	public void flush(){
		out.flush();
	}
	
	public void close(){
		out.close();
	}
	
	private PrintWriter out;
}
