inp = list(map(int,input().split())) h = inp[1] m = (inp[2] + inp[3] * (inp[0] - 1)) if m > 60: h += m // 60 m = m % 60 for a in (h,m): print(a)