#include #include #include #include #include #include using namespace std; #define LL long long #define inf 0x3f3f3f3f #define MP make_pair #define mxn 24 * 70 int c[mxn]; int f( int h, int m ) { return h * 60 + m; } int main() { int cas; scanf( "%d", &cas ); while( cas-- ) { memset( c, 0, sizeof( c ) ); int n; scanf( "%d", &n ); for( int i = 1; i <= n; ++i ) { int x, h, m; scanf( "%d %d:%d", &x, &h, &m ); int t = f( h, m ); c[t] += x; scanf( "%d:%d", &h, &m ); t = f( h, m ); c[t] -= x; } int ans = c[0]; for( int i = 1; i < mxn; ++i ) { c[i] = c[i-1] + c[i]; ans = max( ans, c[i] ); } printf( "%d\n", ans ); } return 0; }