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