Given each train's departure and arrival times plus a turnaround time, find the minimum trainsets needed at stations A and B to run the timetable.
Medium4GreedySortingIntervalsNo attempts yetTime limit5sMemory limit512 MBA railway line has exactly two stations, A and B.

Over one day trains run from A to B and from B to A several times. When a train arrives at B from A (or at A from B), it needs a turnaround time before it can leave again in the opposite direction. For example, if a train arrives at 12:00 and the turnaround time is 0 minutes, that train may leave at 12:00.
The timetable lists the departure time and the arrival time of every train between A and B. The railway company needs to know how many trainsets it has to place at A and at B before the day starts in order to run the timetable. A train can leave A or B only if a trainset that has finished its turnaround is standing at that station. The track between the two stations has passing loops, so trains do not have to arrive in the order they departed. No train other than those in the timetable runs.
Find the minimum number of trainsets that must be placed at A and at B.
The first line contains the number of test cases N.
Each test case spans several lines. The first line holds the turnaround time T in minutes. The next line holds two integers separated by a space: NA, the number of trains from A to B, and NB, the number of trains from B to A. The next NA lines describe the trains from A to B, one per line.
Each of those lines holds a departure time and an arrival time in HH:MM format, separated by a space. Every train departs earlier than it arrives, and every departure and arrival happens within the same day. Hours and minutes are written with two digits each, padded with a leading zero, on a 24 hour clock from 00:00 to 23:59.
After the NA lines, NB lines give the departure and arrival times of the trains from B to A in the same format.
Limits
For each test case print one line starting with Case #x: , followed by the number of trainsets that must be placed at A and the number that must be placed at B, separated by a space. Here x is the test case number, counting from 1.