#include using namespace std; int main() { int tests; scanf("%d", &tests); for(int qq(1); qq <= tests; qq++) { int n; scanf("%d", &n); map mp; for(int i(1); i <= n; i++) { int l, r, a, b, c; scanf("%d%d%d%d%d", &l, &r, &a, &b, &c); mp[0] += c; mp[l * 2] += a - c; mp[r * 2 + 1] += b - a; } long long cur(0), ans(0); for(map::iterator itr(mp.begin()); itr != mp.end(); itr++) { cur += itr->second; ans = max(ans, cur); } cout << ans << endl; } }