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