#include using namespace std; using lint = long long int; using P = pair; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr int INF = 2147483647; void yes(bool expr) { cout << (expr ? "Yes" : "No") << "\n"; } vector> mp(4); lint solve(lint x, lint y, map &m) { lint ret = 0; vector erasekey; lint l = -1; lint r = m.size(); while(r-l > 1) { lint x = (l+r) / 2; if(y > next(m.begin(), x)->second) { r = x; } else { l = x; } } lint lastkey = 0; if(r > 0) lastkey = next(m.begin(), r-1)->first; //cout << r << " " << lastkey << endl; for(auto itr=next(m.begin(), r); ; itr++) { if(itr == m.end()) { if(x > lastkey) { ret += (x - lastkey) * y; m[x] = y; } break; } lint key = itr->first; lint val = itr->second; if(x > key) { if(y > val) { ret += (key-lastkey) * (y-val); erasekey.push_back(key); } } else { if(y > val) { ret += (x - lastkey) * (y-val); m[x] = y; } break; } lastkey = key; } REP(i, erasekey.size()) m.erase(erasekey[i]); return ret; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; REP(i, N) { lint xa, ya, xb, yb; cin >> xa >> ya >> xb >> yb; lint ans = 0; ans += solve(xb, yb, mp[0]); //cout << ans << "\n"; ans += solve(-xa, yb, mp[1]); //cout << ans << "\n"; ans += solve(xb, -ya, mp[2]); //cout << ans << "\n"; ans += solve(-xa, -ya, mp[3]); cout << ans << "\n"; } }