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