import java.io.BufferedReader;
import java.io.FileReader;
import java.util.StringTokenizer;

public class Main {

	/**
	 * @param args
	 * @throws Exception 
	 */
	
	public static int NOD( int a, int b )
	{
		int p;
		a = Math.abs(a);
		b = Math.abs(b);
		
		if ( b > a )
		{
			p = a;
			a = b;
			b = p;
		}
		
		while ( b > 0)
		{
			p = b;
			b = a%b;
			a = p;
		}
		
		return a ;
	}
	public static void main(String[] args) throws Exception {
		BufferedReader in=new BufferedReader(new FileReader("SEGMENT.in"));
		int n=Integer.parseInt(in.readLine());
		for (int i = 0; i < n; i++) {
			StringTokenizer st=new StringTokenizer(in.readLine());
			int x1=Integer.parseInt(st.nextToken()),y1=Integer.parseInt(st.nextToken()),x2=Integer.parseInt(st.nextToken()),y2=Integer.parseInt(st.nextToken());
			if (x1 == x2) {
				System.out.println(Math.abs(y2 - y1) + 1);
				continue;
			}
			if (y1 == y2) {
				System.out.println(Math.abs(x2 - x1) + 1);
				continue;
			}
			
			int k1 = Math.abs(y2-y1),	k2 = Math.abs(x2-x1);
			k2=k2/NOD(k1,k2);
									
			System.out.println((Math.abs(x2-x1)/k2)+1);
			int a =0;
			a++;
		}
	}
}
