Daylight Saving Time

Daylight Saving Time (DST) is the practice of advancing clocks forward during the summer time, usually by one hour, to gain an extra hour of sunlight in the evenings, at the cost of darker mornings. Countries and regions have changed their DST practices over the years, sometimes changing the dates they switch the clocks, and other times changing the amount of minutes the clock changes by.

This creates a real hassle. Sleep cycles are disrupted, operating systems and other computer software needs to follow special rules, and sometimes people end up late to work because of it.

To help make this easier on people, you’ve decided to make a computer program which calculates the new time after an adjustment.


Input consists of a single integer $N$ ($1 \le N \le 500$) indicating the number of test cases that follow. Each test case consists of a single line with the following information:

  • a single character to indicate whether the clock will roll forwards (F) or backwards (B),

  • an integer $D$ ($0 \le D \le 120$) indicating the number of minutes to change by,

  • an integer $H$ ($0 \le H < 24$) indicating the hour the clock currently reads (without leading zeros), and

  • an integer $M$ ($0 \le M < 60$) indicating the minutes the clock currently reads.


For each test case, give the time (hours in $24$-hour format, followed by a space, followed by minutes) after the adjustment has occurred, one test case per line. You may report the numbers without leading zeros.

Sample Input 1 Sample Output 1
F 60 13 20
14 20
Sample Input 2 Sample Output 2
B 45 9 0
F 20 23 50
B 30 0 5
B 60 2 0
F 0 12 0
F 15 17 45
B 0 0 0
8 15
0 10
23 35
1 0
12 0
18 0
0 0