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