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