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