Sliding Values#12284

Sliding Values

1 second
256 megabytes
Hard

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):

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.

Input

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

Output the minimum value of the expression for each test case on a separate line.

Examples

Example 1

Loading
Loading

Note

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.

Scoring

  1. Subtask ( points) : Value assigned to any non-leaf node is .

  2. Subtask ( points) : The degree of node is n-1.

  3. Subtask ( points) : There are exactly 2 leaves in the tree.

  4. Subtask ( points) : (\sum n \le 500) and (1 \le a_i \le 100).

  5. Subtask ( points) : No additional constraints.