from datetime import datetime, timedelta n, h, m, t = map(int, input().split()) dt = datetime(2000, 1, 1, h, m) x = t * (n - 1) dt += timedelta(minutes=x) print(dt.hour) print(dt.minute)