N, H, M, T = map(int, input().split()) a = T * (N-1) H += (a + M) // 60 M = (a + M) % 60 print(H % 24) print(M)