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