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