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