# Tree Edges Coloring

# Tree Edges Coloring

You are given a tree **T** of **n** nodes. The nodes in the tree are numbered **1** through **n**. Let's consider some set of different colors numbered **1** through **n** − **1**. Each color costs differently. You are given a sequence `cost`

, _{1}`cost`

, ..., _{2}`cost`

of the color costs._{n−1}

For each edge, you should choose exactly one color in such a way that no two incident edges have the same color and the sum of the chosen color costs is as minimal as possible.

More formally, let's assign some unique integer from **1** to **n** − **1** to each of the edges of **T**. A sequence `c`

, _{1}`c`

, ..., _{2}`c`

(_{n−1}**1** ≤ `c`

≤ _{k}**n** − **1**) is called an edge coloring of the tree; `c`

is called the color of the _{k}**k**'th edge. An edge coloring is called valid, if there is no such a pair of edges, that share a common node and have the same color.

The cost of an edge coloring is the sum of the color costs for all the edges of the tree. Your task is to find the cost of the cheapest valid edge coloring.

#### Input

The first line contains one integer **t** (**1** ≤ **t** ≤ **16**) denoting the number of test cases in the input.

The first line of each test case description contains an integer **n** (**1** ≤ **n** ≤ **100**). The second line contains **n** − **1** positive integers denoting `cost`

, _{1}`cost`

, ..., _{2}`cost`

(_{n−1}**1** ≤ `cost`

≤ _{color}**1000**). Each of the next **n** − **1** lines contains two integers **u** and **v** denoting an edge of the tree.

#### Output

For each test case, output a single integer: the cost of the cheapest valid edge coloring.

2 5 1 2 3 4 1 2 2 3 2 4 4 5 6 16 4 1 8 2 1 3 3 5 6 3 3 2 4 3

7 31