io.write((function (n, h, m, t) local a = m+t*(n-1) return (h+math.floor(a/60))%24, "\n", a%60, "\n" end)(io.stdin:read("*n"), io.stdin:read("*n"), io.stdin:read("*n"), io.stdin:read("*n")))