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