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