#include <stdio.h>
#include <iostream>

using namespace std;

int nod (int a, int b) {
    return a == 0 ? b : nod(b%a,a);
}

void solve() {
    int x1,y1,x2,y2;

    cin >> x1 >> y1 >> x2 >> y2;

    int dx = x1-x2;
    int dy = y1-y2;
    if (dx < 0) dx = -dx;
    if (dy < 0) dy = -dy;

    cout << nod(dx,dy) + 1 << endl;

    //cout << dx << " " << dy << endl;

}

int main()
{
    //fstream fin("SHADOOF.IN");
    freopen("SEGMENT.IN", "r",stdin);
    int n;
    cin >> n;

    for(int ii = 0; ii < n; ++ii)
    {
        solve();
    }

    return 0;
}
