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