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