Sponsored
Use these hints if you're stuck. Try solving on your own first.
Get the LCA of p and q.
The answer is the sum of distances between p-LCA and q-LCA
Solve with full IDE support and test cases