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