n,h,m,t = map(int, input().split())
tm = h * 60 + m
tm += t*(n-1)
tm %= 60*24
print(tm // 60)
print(tm % 60)