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