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