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