def solve(): N, H, M, T = list(map(int, input().split())) M += T * (N - 1) H += M // 60 H %= 24 M %= 60 print(H) print(M) if __name__ == '__main__': solve()