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