#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ int _t; cin>>_t; rep(_,_t){ long long a,b,c,d; cin>>a>>b>>c>>d; vector va = {0,1,a,c,2},vb = {0,1,b,d,2}; int s = va.size(); vector dis(s,vector(s,Inf64)); dis[2][2] = 0; priority_queue,vector>,greater>> Q; Q.emplace(0,2*s + 2); while(Q.size()>0){ long long D = Q.top().first; int x = Q.top().second/s; int y = Q.top().second%s; Q.pop(); if(dis[x][y]!=D)continue; rep(i,s){ rep(j,s){ if(va[i]==vb[j])continue; if(i==x){ long long DD = D; if(j==0)DD++; else{ if(vb[y] <= va[x] && va[x] <= vb[j])continue; if(vb[y]>vb[j])continue; DD += abs(vb[y] - vb[j]); } if(dis[i][j]>DD){ dis[i][j] = DD; Q.emplace(DD,i*s+j); } } if(j==y){ long long DD = D; if(i==0)DD++; else{ if(va[x] <= vb[y] && vb[y] <= va[i])continue; if(va[x]>va[i])continue; DD += abs(va[x] - va[i]); } if(dis[i][j]>DD){ dis[i][j] = DD; Q.emplace(DD,i*s+j); } } } } } cout<