Naive approach: preprocessing, per query. For queries with , that is total. Binary lifting: preprocessing, per query. Total: . If is large, binary lifting is orders of magnitude faster. For and , naive takes billions of operations.
Binary lifting takes millions. That is the difference between timing out and passing comfortably.