Train Timetable (Large)
Time limit5sMemory limit512 MB
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.
Problem
A 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.
Input
The first line contains the number of test cases .
Each test case spans several lines. The first line holds the turnaround time in minutes. The next line holds two integers separated by a space: , the number of trains from A to B, and , the number of trains from B to A. The next 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 lines, lines give the departure and arrival times of the trains from B to A in the same format.
Limits
Output
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 is the test case number, counting from 1.