You are given a tree that consists of n nodes. You should label each of its n-1 edges with an integer in such way that satisfies the following conditions: 

  * each integer must be greater than 0; 
  * the product of all n-1 numbers should be equal to k; 
  * the number of 1-s among all n-1 integers must be minimum possible. 



Let's define f(u,v) as the sum of the numbers on the simple path from node u to node v. Also, let ∑_{i=1}^{n-1} ∑_{j=i+1}^n f(i,j) be a distribution index of the tree.

Find the maximum possible distribution index you can get. Since answer can be too large, print it modulo 10^9 + 7.

In this problem, since the number k can be large, the result of the prime factorization of k is given instead.

Input

The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.

The first line of each test case contains a single integer n (2 ≤ n ≤ 10^5) — the number of nodes in the tree.

Each of the next n-1 lines describes an edge: the i-th line contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n; u_i ≠ v_i) — indices of vertices connected by the i-th edge.

Next line contains a single integer m (1 ≤ m ≤ 6 ⋅ 10^4) — the number of prime factors of k.

Next line contains m prime numbers p_1, p_2, …, p_m (2 ≤ p_i < 6 ⋅ 10^4) such that k = p_1 ⋅ p_2 ⋅ … ⋅ p_m.

It is guaranteed that the sum of n over all test cases doesn't exceed 10^5, the sum of m over all test cases doesn't exceed 6 ⋅ 10^4, and the given edges for each test cases form a tree.

Output

Print the maximum distribution index you can get. Since answer can be too large, print it modulo 10^9+7.

Example

Input


3
4
1 2
2 3
3 4
2
2 2
4
3 4
1 3
3 2
2
3 2
7
6 1
2 3
4 6
7 3
5 1
3 6
4
7 5 13 3


Output


17
18
286

Note

In the first test case, one of the optimal ways is on the following image:

<image>

In this case, f(1,2)=1, f(1,3)=3, f(1,4)=5, f(2,3)=2, f(2,4)=4, f(3,4)=2, so the sum of these 6 numbers is 17.

In the second test case, one of the optimal ways is on the following image:

<image>

In this case, f(1,2)=3, f(1,3)=1, f(1,4)=4, f(2,3)=2, f(2,4)=5, f(3,4)=3, so the sum of these 6 numbers is 18.
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;

public class MaxDistTree
{	public static StringBuilder result;
	public static ArrayList<ArrayList<Integer>> adj;
	public static ArrayList<Long> val;
	static long n;
	public static long mod(long x)
	{
		return ((x%mod)+mod)%mod;
	}
	public static long add(long a,long b)
	{
		return mod(mod(a)+mod(b));
	}
	public static long mul(long a,long b)
	{
		return mod(mod(a)*mod(b));
	}
	static int mod=(int)(1e9)+7;
	public static long dfs(int s,int p)
	{
		long ans=1;
		for(int u:adj.get(s))
		{
			if(u!=p)
			{
				long nt=dfs(u,s);
				val.add(nt*(n-nt));
				ans+=nt;
			}
		}
		return ans;
	}
	public static void solve() throws IOException
    {
		n=nl();
		adj=new ArrayList<>();
		val=new ArrayList<>();
		for(int i=0;i<n;i++)
			adj.add(new ArrayList<>());
		for(int i=0;i<n-1;i++)
		{
			int u=ni();
			int v=ni();
			adj.get(u-1).add(v-1);
			adj.get(v-1).add(u-1);
		}
		int p=ni();
		ArrayList<Long> fact=new ArrayList<>();
		for(int i=0;i<p;i++)
			fact.add(nl());
		dfs(0,-1);
		Collections.sort(val,Collections.reverseOrder());
		long ans=0;
		for(int i=p;i<n-1;i++){
			fact.add(1L);
		}
		Collections.sort(fact,Collections.reverseOrder());
		if(fact.size()>(n-1))
		{
			int x=0;
			for(int i=0;i<fact.size();i++)
			{
				if(i<(fact.size()-(n-1))){
					fact.set(i+1,mul(fact.get(i),fact.get(i+1)));
				}
				else
					ans=add(ans,mul(fact.get(i),val.get(x++)));
			}
		}
		else
		{
			for(int i=0;i<fact.size();i++)
			{
				ans=add(ans,mul(fact.get(i),val.get(i)));
			}
		}	
		pln(ans);
	}
	static AnotherReader sc;
    static PrintWriter out;
	public static void main (String[] args) throws java.lang.Exception
	{
		boolean oj = true;
        if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
        else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
        int t=1;
		result=new StringBuilder();
		t=ni();
		long s = System.currentTimeMillis();
        while(t-->0)
			solve();
		//pln(((System.currentTimeMillis() - s)/1000.0) + "s");
		out.flush();out.close();  
	}
	static void pln(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
	static boolean isPowerOfTwo (int x) throws IOException{ return x!=0 && ((x&(x-1)) == 0);} //1000(8) & 1111(7)==0
	static boolean isPrime2(long n)throws IOException{ return BigInteger.valueOf(n).isProbablePrime(1);}
	static BigInteger factorial(long n) throws IOException{BigInteger res = BigInteger.ONE;for(long i=1;i<=n;i++)res = res.multiply(BigInteger.valueOf(i)); return res;}
	static boolean isPrime(long n){if(n<2)return false;if(n==2 || n==3)return true;for(int i=1;i*i<=n;i++){long a=6*i+1;long b=6*i-1;if(n%a==0 || n%b==0)return false;}return true;}
 
 
    static class AnotherReader{BufferedReader br; StringTokenizer st;AnotherReader()throws FileNotFoundException{br=new BufferedReader(new InputStreamReader(System.in));}AnotherReader(int a)throws FileNotFoundException{br = new BufferedReader(new FileReader("input.txt"));}String next()throws IOException{while (st == null || !st.hasMoreElements()) {try{st = new StringTokenizer(br.readLine());}catch (IOException  e){e.printStackTrace(); }}return st.nextToken();}int nextInt() throws IOException{return Integer.parseInt(next());}long nextLong() throws IOException{return Long.parseLong(next());}double nextDouble()throws IOException {return Double.parseDouble(next()); }String nextLine() throws IOException{ String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();} return str;}} 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}