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