#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; const ll INF=1LL<<60; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector>; using pli=pair; template bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } vector dijkstra(Graph G,int s){ int n=G.size(); vector dist(n,INF); dist[s]=0; priority_queue,greater> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } return dist; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; cin>>t; while(t--){ Graph G(6); ll a,b,c,d; cin>>a>>b>>c>>d; G[0].push_back(Edge(3,1)); G[0].push_back(Edge(4,1)); if(a>b && c>d && c>=a && d>=b) G[0].push_back(Edge(5,c+d-a-b)); if(a=a && d>=b) G[0].push_back(Edge(5,c+d-a-b)); G[1].push_back(Edge(2,3)); G[2].push_back(Edge(1,3)); if(c>d) G[1].push_back(Edge(5,c+d-1)); else G[2].push_back(Edge(5,c+d-1)); if(a>1) G[3].push_back(Edge(2,2)); if(b>1) G[4].push_back(Edge(1,2)); if(a==1) G[3].push_back(Edge(1,0)); if(b==1) G[4].push_back(Edge(2,0)); if(c>d && c>=a) G[3].push_back(Edge(5,c+d-a)); if(c=b) G[4].push_back(Edge(5,c+d-b)); vector dis=dijkstra(G,0); cout<