TTTABLE - Train TimeTable


A train line has two stations on it, A and B. Trains can take trips from A to B or from B to A multiple times during a day. When a train arrives at B from A (or arrives at A from B), it needs a certain amount of time before it is ready to take the return journey - this is the turnaround time. For example, if a train arrives at 12:00 and the turnaround time is 0 minutes, it can leave immediately, at 12:00.

A train timetable specifies departure and arrival time of all trips between A and B. The train company needs to know how many trains have to start the day at A and B in order to make the timetable work: whenever a train is supposed to leave A or B, there must actually be one there ready to go. There are passing sections on the track, so trains don't necessarily arrive in the same order that they leave. Trains may not travel on trips that do not appear on the schedule.

Input

The first line of input gives the number of cases, N (1<=N<=100). N test cases follow.

Each case contains a number of lines. The first line is the turnaround time, T (0<=T<=60), in minutes. The next line has two numbers on it, NA and NB. NA is the number of trips from A to B, and NB is the number of trips from B to A (0<=NA, NB<=100). Then there are NA lines giving the details of the trips from A to B.

Each line contains two fields, giving the HH:MM departure and arrival time for that trip. The departure time for each trip will be earlier than the arrival time. All arrivals and departures occur on the same day. The trips may appear in any order - they are not necessarily sorted by time. The hour and minute values are both two digits, zero-padded, and are on a 24-hour clock (00:00 through 23:59).

After these NA lines, there are NB lines giving the departure and arrival times for the trips from B to A.

Output

For each test case, output one line containing "Case #x: " followed by the number of trains that must start at A and the number of trains that must start at B.

Example

Input:
2
5
3 2
09:00 12:00
10:00 13:00
11:00 12:30
12:02 15:00
09:00 10:30
2
2 0
09:00 09:01
12:00 12:02 

Output:
Case #1: 2 2
Case #2: 2 0 

hide comments
Insomniac: 2016-02-28 12:32:43

some tricky test cases ????????

Deepak Singh Tomar: 2015-12-12 15:43:08

Taught me a thing or two about implementation! Nice implementation problem.

512_I: 2011-05-11 18:31:59

@abhijith: i got it :)

Last edit: 2011-05-11 18:36:43
Marwan : 2011-02-25 19:31:21

i think this means that the only available trips are those which are mentioned in the statement

Last edit: 2011-02-25 19:31:41
abhijith reddy d: 2009-05-07 11:55:46

sorry...its done nw ! Thanks

Ahmed Kamel [ahm.kam_92]: 2009-05-07 11:55:22

Watch out: the constraints is wrong..
NA and NB have to be (0<=NA,NB<=100).

Have Fun!

Omar ElAzazy: 2009-05-07 11:55:22

(0<=NA,NB<=60).

in the problem statment in googlecode jam it was <= 100 and when submiting now it seems that it is not 60 but 100 can anyone fix this bad copy of the problem ?


Added by:abhijith reddy d
Date:2009-04-27
Time limit:0.106s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Google Codejam 2008