You are given a tree with nodes, rooted at node . Each node has a positive integer value assigned to it. You are allowed to perform the following operation any number of times (possibly zero):
Take the value of any non-leaf node (say ) and split it into two non-negative integers and such that \text{val}[u] = a + b, where (a,b \ge 1).
Add to the value of one of the children of .
Subtract from the value of .
Your task is to minimize:
\max({\text{val}[\ell]∣ \ell \in L})−\min({\text{val}[\ell]∣\ell \in L})
, where is the set of all leaf nodes.
The first line contains a positive integer (1 \le t \le 10^4) — the number of test cases.
The first line of each test case contains an integer where (3 \le n \le 10^5) is the number of nodes present in the tree.
The second line of each test case contains an array of positive integers, where a_i (1 \le a_i \le 10^9) is the value assigned to node .
The following n-1 lines contain space separated integers (1 \le u,v \le n ; u \neq v) — denoting that there exists an edge between and .
It is guaranteed that \sum n \le 10^5 overall tests.
It is guaranteed that the degree of node 1 is 2.
Output the minimum value of the expression for each test case on a separate line.
Example 1
In the first example, the graph is as following:
We're allowed to slide the value of root to leaf by and then you've
This state is the minimum state which for two leaves the \min=4-3=1.
Subtask ( points) : Value assigned to any non-leaf node is .
Subtask ( points) : The degree of node is n-1.
Subtask ( points) : There are exactly 2 leaves in the tree.
Subtask ( points) : (\sum n \le 500) and (1 \le a_i \le 100).
Subtask ( points) : No additional constraints.