n,h,m,t=map(int,input().split()) while n>1: if m>59-t:t=-~t%24 m=(m+t)%60 n-=1 print(h) print(m)