n, h, m, t = map(int, input().split()) m += t*(n-1) while True: if m < 60: h %= 24 break m -= 60 h += 1 print('{}\n{}\n'.format(h,m))