Train Timetable (Small)

Given a day's timetable and a turnaround time, find the minimum number of trains that must start the day parked at each of the two stations.

Medium4GreedySortingSimulationImplementationInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

A railway line has two stations, station A and station B.

The line connecting station A and station B

Trains may run several times a day from A to B, or from B to A. 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 can leave the station right at 12:00.

The timetable lists the departure time and the arrival time of every train that runs between A and B. The railway company needs to know how many cars to park at A and at B before the day starts so that the timetable can be kept. A train can leave a station only if a car is ready to depart there. A ready car is either a car parked at that station before the day starts, or a car that arrived at that station from the other station and has completed its turnaround time.

The track between the two stations has a passing loop, so trains do not have to arrive in the same order they departed. No train other than the ones written in the timetable runs at all.

Find the minimum number of cars that must be parked at station A and the minimum number of cars that must be parked at station B in order to follow the timetable exactly.

Input

The first line holds the number of test cases NN.

Each test case spans several lines. Its first line holds the turnaround time TT in minutes. The next line holds the number of trains from A to B, NAN_A, and the number of trains from B to A, NBN_B, separated by a space. The following NAN_A lines each describe one train from A to B, and the NBN_B lines after them each describe one train from B to A.

Each train line holds a departure time and an arrival time in HH:MM format, separated by one space. Every train departs earlier than it arrives, and every departure and arrival happens within the same single day. Hours and minutes are both written with two digits, padded with 0, on a 24 hour clock from 00:00 to 23:59.

Constraints

  • 1N1001 \le N \le 100
  • 0NA,NB200 \le N_A, N_B \le 20
  • 0T50 \le T \le 5

Output

For each test case, print one line in the format Case #x: a b. Here xx is the test case number starting from 1, aa is the minimum number of cars to park at station A before the day starts, and bb is the same number for station B. Separate aa and bb with one space.