Barbershop#1587

Barbershop

1 second
64 megabytes
Very easy

In the barbershop, there is one master barber. The barber spends exactly minutes on each client, and then immediately proceeds to the next client in line if someone is waiting, or waits until the next customer arrives.

The arrival times of the clients to the barbershop are given (in the order in which they arrived).

Each client also has a characteristic called the degree of impatience. This is the maximum number of people (including the one being served) who can be in the queue ahead of the client so that the client is willing to wait their turn. If, at the moment of a client's arrival, there are more people in the queue than the client's degree of impatience, the client decides not to wait and leaves. The client who is currently being served is also counted as being in the queue.

For each client, you need to specify the time at which they leave the barbershop.

Input

The first line contains the natural number (1 \le N \le 100) — the number of clients.

The following lines contain the clients' arrival times and degrees of impatience. Each line has two numbers indicating hours and minutes (hours — from to , minutes — from to ), and the degree of impatience (a non-negative integer not exceeding ) — the maximum number of people in front of them in the queue they are willing to wait for. The times are listed in ascending order (all times are distinct).

It is guaranteed that all clients will be served before midnight.

If, for some clients, the end time of service for one client matches the arrival time of another, the service for the first client finishes before the second client arrives.

Output

Print pairs of numbers: the leaving times from the barbershop of the st, nd, ..., -th clients (hours and minutes). If, at the moment of a client's arrival, the number of people in the queue exceeds the client's degree of impatience, their leaving time is considered equal to their arrival time.

Examples

Example 1

Loading
Loading