#include #include using namespace std; int main(){ int total_testcases; scanf("%d", &total_testcases); for (int testcase_i = 1; testcase_i <= total_testcases; ++testcase_i){ int A, B, C, D; scanf("%d %d %d %d", &A, &B, &C, &D); auto solve = [&](){ if(C < A && D < B) return C + D + 2; if(D < B) tie(A, B, C, D) = make_tuple(B, A, D, C); if(C < A) return D < C ? C + D + 2 + int(B == 1) : C + 1 + D - B; if((A < B) ^ (D < C)) return C - A + D - B; if(B < A) tie(A, B, C, D) = make_tuple(B, A, D, C); return C - A + D + 1; }; printf("%d\n", solve()); } return 0; }