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.io.*;
import java.util.*;

public class Coding {

    static long MOD = 1000000007;
    static long[] fact = new long[100002];
    static long[] pow2 = new long[100002];

    public static void main(String[] args) {
        BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        //precompute();
        try {
            int t = Integer.parseInt(bi.readLine());
            while (t > 0) {
                int n = Integer.valueOf(bi.readLine());
                List<Integer>[] adj = new ArrayList[n+1];
                long[] nodeCount = new long[n+1];
                for(int i=0;i<=n;++i) {
                    adj[i] = new ArrayList<>();
                    nodeCount[i] = 1;
                }
                for(int i=1;i<=n-1;++i) {
                    String input = bi.readLine();
                    int x = Integer.parseInt(input.split(" ")[0].trim());
                    int y = Integer.parseInt(input.split(" ")[1].trim());
                    adj[x].add(y);
                    adj[y].add(x);
                }
                int m = Integer.parseInt(bi.readLine());
                List<Long> factors = new ArrayList<>();
                String[] inputs = bi.readLine().split(" ");
                for(int i=0;i<m;++i) {
                    factors.add(Long.parseLong(inputs[i].trim()));
                }
                Collections.sort(factors);
                long[] wt = new long[n+1];
                for(int i=0;i<=n;++i) {
                    wt[i] = 0;
                }
                dfs(1, adj, nodeCount, -1);
                List<Long> weights = new ArrayList<>();
                for(int i=2;i<=n;++i) {
                    weights.add(nodeCount[i]*(n-nodeCount[i]));
                }
                Collections.sort(weights);
                long ans = 0;
                int count = 0;
                for(int i=n-2;i>=0;--i) {
                    if (m-1-count<0) {
                        ans = ans + weights.get(i);
                        ans%=MOD;
                    } else {
                        long val = 1;
                        while(m-1-count>i) {
                            val = val*factors.get(m-1-count);
                            val = val%MOD;
                            count++;
                        }
                        val = val*factors.get(m-1-count);
                        val%=MOD;
                        ans = ans + weights.get(i)*val;
                        ans%=MOD;
                        count++;
                    }
                }
                writer.append(String.valueOf(ans));

                writer.append('\n');
                writer.flush();
                t--;
            }
            writer.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private static int gcd(int a, int b) {
        if (a%b==0) {
            return b;
        }
        return gcd(b, a%b);
    }

    private static void dfs(int cur, List<Integer>[] adj, long[] nodeCount, int parent) {
        for(int i=0;i<adj[cur].size();++i) {
            int nxt = adj[cur].get(i);
            if (nxt!=parent) {
                dfs(nxt, adj, nodeCount, cur);
                nodeCount[cur]+=nodeCount[nxt];
            }
        }
    }

    private static int findDist(int a, int b, int[] par) {
        Map<Integer, Integer> dist = new HashMap<>();
        int count = 0;
        dist.put(a, 0);
        while (par[a]!=-1) {
            a = par[a];
            count++;
            dist.put(a, count);
        }
        count=0;
        while(!dist.containsKey(b)) {
            b = par[b];
            count++;
        }
        return count+dist.get(b);
    }

    private static int findLongestPath(int cur, int prev, List<Integer>[] adj, int[] dep) {
        int diameter = 0;
        int highest = -1, second=-1;
        for(int i=0;i<adj[cur].size();++i) {
            int nxt = adj[cur].get(i);
            if (nxt!=prev) {
                diameter = Math.max(diameter, findLongestPath(nxt, cur, adj, dep));
                if (dep[nxt]>highest) {
                    second = highest;
                    highest = dep[nxt];
                } else if (dep[nxt]>second) {
                    second = dep[nxt];
                }
            }
        }
        diameter = Math.max(diameter, highest + second + 2);
        return diameter;
    }

    static long ncr(int n, int r) {
        long num = fact[n];
        long denom = (modExp(fact[r], MOD-2)*modExp(fact[n-r], MOD-2))%MOD;
        //System.out.println("num is " + num + " denom is" + denom);
        return (num*denom)%MOD;
    }

    static long modExp(long a, long b) {
        //System.out.println("a is " + a + " and b is " + b);
        if (a==1) return 1;
        long ans = 1;
        while (b!=0) {
            if (b%2==1) {
                ans = (ans*a)%MOD;
            }
            a = (a*a)%MOD;
            b/=2;
        }
        return ans;
    }

    private static void precompute() {
        fact[0] = 1;
        pow2[0] = 1;
        for(int i=1;i<=100000;++i) {
            fact[i] = (fact[i-1]*i)%MOD;
            pow2[i] = (pow2[i-1]*2)%MOD;
        }
    }
}
