n, h, m, t = [int(x) for x in input().split()] mm = h * 60 + m res_m = mm + (n - 1) * t print(res_m // 60 % 24) print(res_m % 60)