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