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