N,H,M,T = map(int,input().split()) time = (N-1)*T a,b = divmod((M+time),60) if a+H >= 24: a = (a+H) % 24 else: a = a + H print(a) print(b)