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