#Lutece1480. Magic boy Bi Luo with his excited Zhu problem

Magic boy Bi Luo with his excited Zhu problem

Migrated from Lutece 1480 Magic boy Bi Luo with his excited Zhu problem

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

As we know, Bi Luo is a magic boy, he always has some excited questions , now a new question comes.

You are given a simple unrooted tree GG , Bi Luo wants you to caculate the excited value of the GG.

At the begining , excited value is 00 , then for each non-empty subset of NN , we just think its vertex-induced subgraph GG^{\ast} , then we think each non-empty subset of NN again, we just think its vertex-induced subgraph GG^{\ast\ast} , if GG^{\ast\ast} is a connected graph and GG^{\ast\ast} completely contained GG^{\ast} , then excited value adds zhuzhu[the number of vertexs in GG^{\ast\ast}] , otherwise do nothing.

Now, Bi Luo wants you to caculate the excited value of GG, can you help him?

Input

First Line is an positive integer TT , ( 1T1001 \leq T \leq 100 ) , represents there are TT test cases.

For each test case:

The first line contains two positive integers NN .( 1N20001 \leq N\leq 2000 ) . represents there are NN vertexs.

The next N1N-1 line, each line contains two integers uu , vv( 1u,vN1 \leq u , v \leq N) , indicating there is an edge between uu and vv.

The next line contains NN integers , represents the elements of zhu[i]zhu[i].( 1zhu[i]1091 \leq zhu[i] \leq 10^9)

You may assume that there are no more than 2525 test cases with 1000<N20001000 < N \leq 2000 .

Output

For tht ii-thth test case , first output Case #i: ,then output one integer repretens the excited value,because the excited value may be large, so you only need to output the excited value of GG mod 152076289152076289

Samples

3
1
1
2
1 2
1 1
3
1 2
2 3
1 1 1
Case #1: 1
Case #2: 5
Case #3: 16

Resources

“玲珑杯”ACM比赛 Round #2