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

public class Main {

    private static class Tree {
        int index;
        ArrayList<Tree> childs;
        Tree(int index) {
            this.index = index;
            childs = new ArrayList<Tree>();
        }
    }

    private static class myGraph {
        int V;
        ArrayList<HashSet<Integer>> adjList;

        myGraph(int V) {
            this.V = V;
            adjList = new ArrayList<HashSet<Integer>>();
            for (int i = 0; i < V; i++) {
                adjList.add(new HashSet<Integer>());
            }
        }

        void addEdge(int u, int v) {
            adjList.get(u).add(v);
            adjList.get(v).add(u);
        }

        Tree rootTree(int s, boolean[] visited) {
            Tree root = new Tree(s);
            visited[s] = true;
            for (int x : adjList.get(s)) {
                if (!visited[x]) {
                    root.childs.add(rootTree(x, visited));
                }
            }
            return root;
        }

        int nodeCount(Tree root, ArrayList<Long> traffic, int n) {
            int totalNode = 1;
            for (Tree child : root.childs) {
                int nodes = nodeCount(child, traffic, n);
                traffic.add((long)nodes * (n - nodes));
                totalNode += nodes;
            }
            return totalNode;
        }

        Boolean isVertex(int u, int v) {
            return adjList.get(u).contains(v);
        }

        void printGraph() {
            System.out.println("graph veteces - >");
            for (int i = 0; i < V; i++) {
                for (Integer integer : adjList.get(i)) {
                    System.out.print(i + "-" + integer + " , ");
                }
            }
            System.out.println();
        }

        void DFS(int s) {
            boolean visited[] = new boolean[V];
            Arrays.fill(visited, false);
            System.out.println("DFS - > ");
            visited[s] = true;
            DFShelper(s, visited);
            System.out.println();
        }

        void DFShelper(int s, boolean visited[]) {
            // System.out.println("stack of " + s + " started");
            if (adjList.get(s).isEmpty()) {
                DFShelper(++s, visited);
                // System.out.println("stack of " + s + " ends");
                return;
            }
            System.out.print(s + " -> ");
            Iterator<Integer> iterator = adjList.get(s).iterator();
            while (iterator.hasNext()) {
                int temp = iterator.next();
                if (visited[temp] == false) {
                    visited[temp] = true;
                    DFShelper(temp, visited);
                }
            }
            // System.out.println("stack of " + s + " ends");
        }

    }

    boolean[] sieveOfEratosthenes(int n)
    {
        boolean isPrime[] = new boolean[n+1];
        Arrays.fill(isPrime , true);
        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2; i * i <= n ; i++)
        {
            for(int j = 2 * i ; j <= n; j += i)
                isPrime[i] = false;
        }
        return isPrime;
    }

    static long modExpo(long x, long y , int mod) {
        if(y == 0) {
            return 1;
        }
        if((y&1) == 0) {
            return modExpo(x * x , y >> 1 , mod);
        }
        long res = modExpo(x , y - 1 , mod) * x;
        return res > mod ? res - mod : res;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder("");
        StringTokenizer st;
        int t = Integer.parseInt(br.readLine());
        while(t-- != 0) {
            int n = Integer.parseInt(br.readLine());
            myGraph graph = new myGraph(n);
            for(int i = 0 ; i < n - 1 ; i++) {
                st = new StringTokenizer(br.readLine());
                int u = Integer.parseInt(st.nextToken());
                int v = Integer.parseInt(st.nextToken());
                graph.addEdge(u - 1 , v - 1);
            }
            int m = Integer.parseInt(br.readLine());
            Integer p[] = new Integer[m];
            st = new StringTokenizer(br.readLine());
            for(int i = 0 ; i < m ; i++) {
                p[i] = Integer.parseInt(st.nextToken());
            }
            System.out.println(Code(graph , n , p , m));
        }
    }

    static long Code(myGraph graph , int n , Integer p[] , int m) {
        ArrayList<Long> traffic = new ArrayList<>();
        Tree root = graph.rootTree(0 , new boolean[n]);
        graph.nodeCount(root , traffic , n);
        traffic.sort(Collections.reverseOrder());
        Arrays.sort(p , Collections.reverseOrder());
        long res = 0;
        int mod = (int)1e9 + 7;
        int trafficSize = n - 1;
        if(m >= trafficSize) {
            long prod = 1;
            for(int i = 0 ; i <= m - trafficSize ; i++) {
                prod = (prod * p[i]) % mod;
            }
            res = (res + (prod * traffic.get(0)) % mod) % mod;
            for(int i = 1 ; i < trafficSize ; i++) {
                res = (res + (traffic.get(i) * p[m - trafficSize + i]) % mod) % mod;
            }
        }
        else {
            for(int i = 0; i < m ; i++) {
                res = (res + (p[i] * traffic.get(i)) % mod) % mod;
            }
            for(int i = m ; i < trafficSize ; i++) {
                res = (res + traffic.get(i)) % mod;
            }
        }
        return res;
    }

}

/*

1000 1000000000 511

*/