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