Hide

Problem E
Friends Across Time

/problems/friendsacrosstime/file/statement/en/img-0001.png
Image by Evansiroky2

While traveling around the world, you often find it hard to figure out what time it is for your friends in other countries. Different time zones and daylight saving rules make it confusing. You decide to write a program that can calculate the local time difference between you and your friends, no matter where each of you are.

To make things easier, you will write a program that determines your friend’s local time based on:

  • your current local time,

  • the standard time difference $D$ (a number between $-12$ and $+12$ in increments of $0.25$). If $D$ is positive, your friend’s standard time is ahead of yours; if negative, it is behind.

  • two integers (each $0$ or $1$) indicating whether daylight saving time (DST) is active for you and for your friend, respectively.

A DST value of $1$ indicates that daylight saving time is active and should add one additional hour. A value of $0$ means DST is not active.

Input

The first line contains an integer $n$ ($1 \le n \le 100$), the number of test cases.

Each of the next $n$ lines contains the following information, separated by spaces:

  • your local time in 24-hour format HH:MM ($00 \le \text{HH} < 24$, $00 \le \text{MM} < 60$),

  • the standard UTC offset difference between your location and your friend’s (a number between $-12$ and $+12$ in increments of $0.25$, given with exactly $2$ decimal places),

  • two integers (each $0$ or $1$) indicating whether daylight saving time (DST) is active for you and for your friend, respectively.

Output

For each test case, output your friend’s local time in 24-hour format HH:MM, adjusted for the offset difference and any applicable daylight saving changes.

Sample Input 1 Sample Output 1
5
14:30 +5.00 1 0
23:00 -3.50 0 1
17:31 +6.00 1 1
03:13 +0.00 0 0
12:45 -9.00 1 1
18:30
20:30
23:31
03:13
03:45

Please log in to submit a solution to this problem

Log in