Read the tree, build parent array.
Build the table:
up[v][0] = parent[v]
up[v][j] = up[up[v][j-1]][j-1]
For each query , jump up steps using the binary lifting technique.
If you reach an invalid node (null or past root), return .
Otherwise, return the final node.
This runs in preprocessing time and per query. Space is for the table.