#P2655. 2038 年问题

2038 年问题

Description

In the network era, opportunities and crises coexist. After the "Y2K bug" was solved, would a new "bug" appear? The answer is yes: "the year 2038" is a new hurdle.

Maybe everyone already knows what the 20002000 year problem in computers is, but when did the 20382038 year problem emerge?

Programs written in C will not encounter the 20002000 year problem, but they will have the 20382038 year problem. This is because most C programs use a "standard time library," which stores time information in a standard 44-byte, that is, 3232-bit, format.

When it was designed, this 44-byte time format took 19701970 year 11 month 11 day at 00 hour 00 minute 00 second as the time origin (value 00). All subsequent times are counted by accumulating seconds from this point.

For example, if the accumulated value has reached 919642718919642718, it means that 919642718919642718 seconds have passed since 19701970 year 11 month 11 day at 00 hour 00 minute 00 second. Converted, it should be Sunday, 19991999 year 22 month 2121 day at 1616 hour 1818 minute 3838 second.

The advantage of calculating time this way is that by subtracting any two time values, you can quickly get the number of seconds between them, and then use other routines to convert it into a human-readable year-month-day hour-minute-second format.

The maximum value of a 44-byte, that is, 3232-bit, storage is 21474836472147483647. Note! The key to the 20382038 year problem lies here—after time ticks through the heart-stopping final second 21474836472147483647, it will overflow into a negative number, meaning the time becomes invalid. The exact moment is Tuesday, 20382038 year 11 month 1919 day at 03:14:0703:14:07. After that, all C programs using this "standard time library" will run into trouble with time calculations.

Your task: given a computer whose time variable has length NN bits and a given "time origin," determine the last valid time with respect to this "time origin."

Input Format

The first line contains the number of test cases TT.

Lines 22 to T+1T+1: each line contains 77 integers describing one test case: the number of bits of the time variable (in binary), followed by the year, month, day, hour, minute, and second of the "time origin."

Output Format

Output TT lines. For each test case, output 11 line with 66 integers: the year, month, day, hour, minute, and second of the last valid time.

1                             
16 2000 1 1 0 0 0
2000 1 1 9 6 7
2
32 1970 1 1 0 0 0
32 2015 11 8 8 30 0
2038 1 19 3 14 7
2083 11 26 11 44 7

Hint

For 50%50\% of the testdata, the number of bits of the variable 16\le 16.

For all testdata, the variable length 32\le 32, the number of test cases 1000\le 1000, and 00 \le year 10000\le 10000.

Translated by ChatGPT 5