The lowest common ancestor of two nodes p and q is the lowest node in the binary tree that has p and q as its descendants.
Note: A node is also considered a descendant of itself.
Given the reference to the root node and two nodes p and q in a binary tree, return the reference to the lowest common ancestor of p and q.
Note: You can assume that p and q will be present in the tree.
The first line contains an integer T denoting the number of test cases.
For each test case, the input has 3 lines:
For each test case, the output contains a line with the value of the lowest common ancestor for p and q.
6
7
1 2 -1 4 -1 5 6
1 5
3
6 -1 4
0 2
7
8 -1 9 -1 10 11 12
2 5
5
28 14 11 -1 48
4 2
1
6
0 0
7
3 -1 2 1 5 -1 6
3 6
2
6
9
28
6
1
1 <= T <= 10
1 <= n <= 105
1 <= node value <= 106