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