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 print(h) print(m)