# 오븐 시계
# https://www.acmicpc.net/problem/2525
# https://github.com/yhs3434

a, b = map(int, input().split(' '))
c = int(input())

b += c
h = b // 60
b %= 60

a += h
a %= 24

print(a, b)
40370dd97311419d59d73e2fa68cf5c55b2dff72
<mask token>

<mask token>
b += c
<mask token>
b %= 60
a += h
a %= 24
print(a, b)

a, b = map(int, input().split(' '))
c = int(input())
b += c
h = b // 60
b %= 60
a += h
a %= 24
print(a, b)

# 오븐 시계
# https://www.acmicpc.net/problem/2525
# https://github.com/yhs3434

a, b = map(int, input().split(' '))
c = int(input())

b += c
h = b // 60
b %= 60

a += h
a %= 24

print(a, b)