n, h, m, t = [int(i) for i in input().split()] m += t * (n - 1) h += m // 60 print(h%24, m%60)