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

#define min(a, b) (((a)<(b))?(a):(b))
#define max(a, b) (((a)>(b))?(a):(b))

typedef long long ll;

using namespace std;

int main(){
    freopen("SEGMENT.IN","r", stdin);
    //freopen("input.txt", "r", stdin);

    int T;

    scanf("%d",&T);
    while(T--){
        int ax,ay,bx,by;
        scanf("%d%d%d%d",&ax,&ay,&bx,&by);

        ll x = abs(ax-bx);
        ll y = abs(ay-by);

        while(x&&y) if(x>y) x%=y; else y%=x;

        cout<<x+y+1<<endl;
    }

    return 0;
}
