N, H, M, T = map(int, input().split()) hun = H*60+M hun += T*(N-1) hun %= 1440 print(hun//60, hun%60, end="\n")