URJC2_A - TV Schedule

no tags 

The schedules of a TV Channel are very important nowadays, it reflects the shows they’re hosting and this can contribute to gather more or less people, hence, making more or great money to them!

You have been called to make a program that, given the current program of the TV shows on the channel, answer the queries of the audience. To answer the query of the audience you must show the next program that follows the one they are currently watching, you may assume that the TV programs are cyclic and the final show ends at 23:59, after that, the first show will begin at 00:00 

 

Input

The first line contains an integer T, which specifies the number of test cases. Then, will follow the descriptions of T test cases.

The first line will be a number N denoting the number of tv shows, then, N lines will follow, each line will contain a start hour in the format HH:MM and the end hour with the same format, then, the name of the program that may contain lowercase, uppercase letters and will not exceed 100 characters.

You can assume that every show will cover the whole day (all 1440 minutes of the day) and that the end date is exclusive (meaning that two consecutive programs will share their end date and start date respectively), it is not guaranteed that a program name will be unique along the day.

After that, you will receive an integer Q denoting the queries that will make the audience, then, Q lines, for each query you will receive an hour with the format HH:MM.

Output

For each case you must print Q lines, each line will contain a string denoting the program that follows the one currently being watched. Note that we consider that the program starts exactly at the given hour.

Sample Input Sample Output
2
3
00:00 12:00 Noticias
12:00 14:00 AquiNoHayQuienViva
14:00 00:00 Informeciales
2
00:51
23:10
5
20:00 23:50 DocumentalDe
00:00 00:06 NoticiasUrgentes
14:00 20:00 LaQueSeAvecina
00:06 14:00 YLoSabes
23:50 00:00 JulioIglesias
3
19:50
23:49
00:00
AquiNoHayQuienViva
Noticias
DocumentalDe
JulioIglesias
YLoSabes



Constraints

• 1 ≤ N ≤ 1440

• 00 ≤ HH ≤ 23

• 00 ≤ MM ≤ 59

• 1 ≤ Q ≤ 100

• 1 ≤ |name of program|≤ 100



Added by:david_8k
Date:2017-03-29
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Own problem