This page is still under construction.

Parts of this page are still being built. What you see may change.

Changyong's Clock

Time limit1sMemory limit512 MB

Summary
Track a clock's time on a 24-hour dial, turning it forward or backward by c seconds and answering queries for the current time.
Level

Easy2 of 10

Topics
Simulation, Math, Implementation
Solved
No attempts yet

Problem

Changyong bought a limited summer edition watch. He took the battery out, so the watch does not advance on its own. The hands move only as far as Changyong turns them.

Changyong turns the watch forward and backward. You are given the time the watch shows at the start and qq queries. Each query begins with TT.

  • If TT is 1, an integer cc follows. Turn the watch forward by cc seconds.
  • If TT is 2, an integer cc follows. Turn the watch backward by cc seconds.
  • If TT is 3, print the time the watch shows at that moment.

The watch runs on a 24-hour dial. Turning it forward by one second from 23:59:59 gives 0:0:0, and turning it backward by one second from 0:0:0 gives 23:59:59.

1≤T≤31 \le T \le 3 and 0≤c≤10 000 0000 \le c \le 10\,000\,000.

Input

The first line contains the starting time as hh mm ss. (0≤h≤230 \le h \le 23, 0≤m≤590 \le m \le 59, 0≤s≤590 \le s \le 59)

The second line contains the number of queries qq. (1≤q≤100 0001 \le q \le 100\,000)

Each of the next qq lines contains one query. A query with TT equal to 1 or 2 gives TT and cc separated by a space, and a query with TT equal to 3 gives only TT.

Output

For every query with TT equal to 3, print the time the watch shows at that moment as h′h' m′m' s′s' on its own line. Separate the three values with a single space and do not pad them with zeros. At least one query has TT equal to 3.

Examples2

  1. Example 1

    Input
    0 1 0
    4
    1 4263
    3
    2 1175
    3
    
    Expected output
    1 12 3
    0 52 28
    
  2. Example 2

    Input
    5 7 9
    1
    3
    
    Expected output
    5 7 9