#include using namespace std; using ll = long long; ll solve(){ ll a, b, c, d; cin >> a >> b >> c >> d; ll ans = 0; if(c < d){ swap(a, b); swap(c, d); } if(a > c){ a = 0; ans++; } //b -> c + 1 -> 0 //b -> 2以上 -> 0 if((a < b && b <= c) || b > d){ ans += 1 + (b == 1 && a == 0); b = 0; } ans += c - a + d - b; return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ cout << solve() << '\n'; } }