#include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << ", " << p.second << ')'; } template::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pi; const int mxN = 1e5+1, oo = 1e9; ll solve(ll a, ll b, ll c, ll d) { if(a>c) return 1+solve(0,b,c,d); if(b>d) return 1+solve(a,0,c,d); if(a==0 and b==0) return c+d; if((a> t; while(t--) { ll a,b,c,d; cin >> a >> b >> c >> d; cout << solve(a,b,c,d) << '\n'; } }