n,h,m,t=map(int,input().split()) m+=(n-1)*t if m>59: m,h=m%60,m//60 if h>23: h=h%24 print('{}\n{}'.format(h,m))