#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int gcd(int a, int b){
    while(a && b){
        if(a>b) a%=b;
        else b%=a;
    }
    return a+b;
}

int main()
{
    freopen("SEGMENT.IN", "r", stdin);
    int t;
    cin >> t;
    for(int l=0; l<t; ++l){
        int x1, y1, x2, y2, s=1;
        cin >> x1 >> y1 >> x2 >> y2;
        int d = gcd(abs(x2-x1), abs(y2-y1));
        int dx = (x2-x1)/d;
        int dy = (y2-y1)/d;
        if(dx != 0) for(int i=x1; i!=x2; i+=dx) s++;
        else for(int i=y1; i!=y2; i+=dy) s++;
        cout << s << endl;
    }
    return 0;
}
