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