n, h, m ,t = map(int, input().split()) m1 = (n-1) * t m = m + m1 h1 = 0 if m > 60: h1 = m//60 m = m - h1*60 h = h + h1 h2 = 0 if h > 24: h2 = h//24 h = h - h2*24 print(h) print(m)