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