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