n, h, m ,t = map(int, input().split()) m += (n-1) * t m = m % 60 h = (h + m//60) % 24 print(h) print(m)