After both nodes are at the same depth, you climb them upward together. Start from the highest power of and work down. For each power , check if up[u][k] != up[v][k]. If they differ, jump both nodes: u = up[u][k] and v = up[v][k]. If they are the same, skip this power and try a smaller one.
When no more jumps are possible without making u and v equal, their direct parent up[u][0] is the LCA. You stop one step before they merge because jumping too far would overshoot. This runs in time per query and uses space for the precomputed table.