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