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