n,h,m,t = map(int,input().split()) m += (n-1)*t if m >= 60: while m >= 60: m -= 60 h += 1 print(int(h%24)) print(m)