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