x = list(map(int,input().split())) n = x[0] h = x[1] m = x[2] t = x[3] m = m + t * (n - 1) h = h + m // 60 m = m % 60 h = h % 24 print(h) print(m)