N, H, M, T = map(int, input().split()) s = (N-1) * T h = H + (s//60) if h >= 24: h = h % 24 print(h) print(s % 60)