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