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