from datetime import datetime, timedelta n, h, m, t = map(int, input().split()) now = datetime(2000, 1, 1, h, m) dt = t * (n - 1) getup = now + timedelta(minutes=dt) ans = getup.hour, getup.minute print(*ans, sep="\n")