Chow, Mo

Limits 1s, 256 MB

Mo, the jumper has found an extraordinary tree in the woods. He absolutely loves it. He already has made quite a few jumps from one branch to another. After a while, being bored, he wonders what would be the minimum time to reach a vertex from another.

Formally, a tree is a connected graph with bidirectional edges and there exists only one path between two vertices. The tree Mo found is rooted at $1$ and has $N$ vertices numbered from $1$ to $N$. Every vertex $i$ has some color $c_i$. It takes him $d$ seconds to go from vertex $u$ to $v$ if $u, ~v$ are adjacent. Also, Mo can jump from a vertex $u$ to vertex $v$ if the colors of those two vertices are same, i.e. $c_u = c_v$. These jumps take him $f_{c_u}$ seconds.

For two vertices $s$ and $t$, find out the minimum time needed for Mo to reach $t$ from $s$.

Input

First line contains an integer $T$.

There are $T$ test cases. For each test case ---

Scoring

Subtask 1 (20 points):

Subtask 2 (30 points):

Subtask 3 (50 points):

Output

For each test case, output the minimum time needed in seconds to reach $t$ from $s$.

Sample

InputOutput
1
8 10
1 2 2 4 4 1 6
3 2 4 4 3 2 1 4
12 20 14 14 12 20 5 14
7 8
44

Mo walks 7-1 in d=10 seconds. 1-2 in another 10 seconds. Then he goes to 3 via 2-3 causing another 10 seconds. Then he jumps from vertex-3 to vertex-8 since they are the same color. This jump takes him 14 seconds. Total time: 44 seconds.


Large input file. Please use faster I/O. (e.g. scanf(), printf() in C/C++)