eolymp
bolt
Try our new interface for solving problems
Problems

Barbershop

Barbershop

In the barber shop has one master. He spends per customer was \textbf{20} minutes and then immediately goes to the next in line if someone is, or is waiting for the next customer comes. Given the arrival times of customers in the barber shop (in the order in which they came). Likewise, each client has hrakteristika called the degree of impatience. It shows how people can make the most is in the queue to the client, so he waited his turn and not gone before. If the arrival of the customer in the queue is more people than the degree of impatience, he decides not to wait for their turn and go. The client, who served at the moment as well considered to be in the queue. Required for each client to specify the time of his exit from the barbershop. \InputFile The first line introduces a positive integer \textbf{N}, does not exceed \textbf{100} - the number of customers. The next \textbf{N} lines are introduced arrival times of customers - by two numbers indicating the hours and minutes (hours - from \textbf{0} to \textbf{23} minutes - \textbf{0} to \textbf{59}) and the degree of impatience (non-negative integer not greater than \textbf{100}) - maximum number of people who he is willing to wait in front of him in line. Times are listed in ascending order (all times are different). It is guaranteed that all customers will have time to serve until midnight. If for some customers end time of one customer service and time of arrival of another match, we can assume that in the beginning of the end of the first customer service, and then comes the second client. \OutputFile The output file output \textbf{N} pairs of numbers: the time of exit from the barber shop of the \textbf{1}st, \textbf{2}nd, ..., \textbf{N}-th customer (hours and minutes). If the arrival of the client's people waiting in line more than a degree of impatience, we can assume that the time of his departure came the same time.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
10 0 0
10 1 1
10 2 1
Output example #1
10 20
10 40
10 2