CSCI-101: Intro to Computer Science
Python Course

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

Input consists of a single integer \(N\) (\(1 \leq N \leq 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 \leq D \leq 120\)) indicating the number of minutes to change by,
  • an integer \(H\) (\(0 \leq H < 24\)) indicating the hour the clock currently reads (without leading zeros),
  • and an integer \(M\) (\(0 \leq M < 60\)) indicating the minutes the clock currently reads.

Output

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.

Lab I/O Format

Your program should use the Lab Input/Output Format, as described below:

  • When prompting for input, use the prompt string WORD>, where WORD is a single, uppercase word which describes the input.
  • When providing output that will be graded, start the line with OUTPUT. Think of this as "boxing your answer" on a math worksheet, it lets us quickly find your answer. We will ignore any lines which do not start with OUTPUT.
  • You may interleave the inputs and outputs in any order you wish. For example, you might want to recieve all of your inputs (order of inputs still matters!), then print all of your outputs (order of outputs still matters!), or you might want to do input/output, input/output, etc.

Example Interaction 1

N> 1
INPUT> F 60 13 20
OUTPUT 14 20

Example Interaction 2

N> 7
INPUT> B 45 9 0
OUTPUT 8 15
INPUT> F 20 23 50
OUTPUT 0 10
INPUT> B 30 0 5
OUTPUT 23 35
INPUT> B 60 2 0
OUTPUT 1 0
INPUT> F 0 12 0
OUTPUT 12 0
INPUT> F 15 17 45
OUTPUT 18 0
INPUT> B 0 0 0
OUTPUT 0 0

Hints

It's easy to get this problem wrong. Come up with more test cases than the sample here. Try to design inputs that would cause your program to fail, then test appropriately. We will test your program on much larger inputs than you see here.