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.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class CodeForce1401D {

    private static final long MOD = 1000000007L;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            process(scanner);
        }
    }

    public static void process(Scanner scanner) {
        int n = scanner.nextInt();
        Graph graph = new Graph(n);
        for (int i = 0; i < n - 1; i++) {
            graph.addEdge(scanner.nextInt(), scanner.nextInt());
        }
        int[] degrees = new int[n + 1];
        int[] counts = new int[n + 1];
        IntArray leafs = new IntArray(n);
        for (int i = 1; i <= n; i++) {
            counts[i] = 1;
            degrees[i] = graph.getEdges(i).size();
            if(degrees[i] == 1) {
                leafs.push(i);
            }
        }
        while(leafs.length > 0) {
            int leaf = leafs.pop();
            for (Edge edge : graph.getEdges(leaf)) {
                if (edge.isVisited()) {
                    continue;
                }
                edge.markVisited();
                int another = edge.getAnotherNode(leaf);
                counts[another] += counts[leaf];
                edge.setSameSideNodes(leaf, counts[leaf]);
                edge.setSameSideNodes(another, n - counts[leaf]);
                if (--degrees[another] == 1) {
                    leafs.push(another);
                }
            }
        }
        long[] weights = new long[n - 1];
        int edgeCount = 0;
        for (Edge edge : graph.edges) {
            weights[edgeCount++] = edge.aSideNodes * edge.bSideNodes;
        }
        calculateSum(scanner, weights);

    }

    private static void calculateSum(Scanner scanner, long[] weights) {
        Arrays.sort(weights);
        for (int i = 0; i < weights.length; ++i) {
            weights[i] = weights[i] % MOD;
        }
        int m = scanner.nextInt();
        int[] ps = new int[m];
        for (int i = 0; i < m; i++) {
            ps[i] = scanner.nextInt();
        }
        Arrays.sort(ps);
        long sum = 0;
        int skip = Math.max(0, weights.length - m);
        for(int i = 0; i < skip; ++i) {
            sum = (weights[i] + sum) % MOD;
        }
        for (int i = skip; i < weights.length; i++) {
            if(i != weights.length - 1) {
                sum = (sum + (weights[i] * ps[i - skip]) % MOD) % MOD;
            }
            else {
                long edgeWeight = 1;
                for(int j = i - skip; j < ps.length; ++j) {
                    edgeWeight = (edgeWeight * ps[j]) % MOD;
                }
                sum = (sum + (weights[i] * edgeWeight) % MOD) % MOD;
            }
        }
        System.out.println(sum);
    }

    public static class IntArray {
        int[] data;
        int length;
        IntArray(int n) {
            this.data = new int[n];
            this.length = 0;
        }

        public void push(int n) {
            this.data[this.length++] = n;
        }

        public int pop() {
            return this.data[--this.length];
        }
    }

    public static class Graph {
        List<List<Edge>> nodeEdges;
        int[] lengths;
        List<Edge> edges;
        Graph(int n) {
            this.nodeEdges = new ArrayList<>();
            for (int i = 0; i <= n; i++) {
                this.nodeEdges.add(new ArrayList<Edge>());
            }
            this.lengths = new int[n + 1];
            this.edges = new ArrayList<>();
        }

        void addEdge(int a, int b) {
            Edge e = new Edge(a, b);
            this.nodeEdges.get(a).add(e);
            this.nodeEdges.get(b).add(e);
            this.edges.add(e);
        }

        List<Edge> getEdges(int a) {
            return this.nodeEdges.get(a);
        }

    }

    static class Edge {
        int a;
        int b;
        long aSideNodes;
        long bSideNodes;
        boolean visited;
        Edge(int a, int b) {
            this.a = a;
            this.b = b;
        }

        int getAnotherNode(int node) {
            return this.a == node ? this.b : this.a;
        }

        void setSameSideNodes(int node, long count) {
            if(this.a == node) {
                this.aSideNodes = count;
            }
            else{
                this.bSideNodes = count;
            }
        }

        void markVisited() {
            this.visited = true;
        }

        boolean isVisited() {
            return this.visited;
        }
    }
}