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.*;

import static java.lang.Math.max;
import static java.lang.Math.min;


/**
 * Created by Katushka on 11.03.2020.
 */
public class C {

    public static final Comparator<int[]> COMPARATOR = Comparator.comparingInt(o -> o[0]);
    private static final long MOD = 1000000007;

    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    static class Edge {
        int u;
        int v;

        public Edge(int u, int v) {
            this.u = u;
            this.v = v;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Edge edge = (Edge) o;
            return u == edge.u &&
                    v == edge.v;
        }

        @Override
        public int hashCode() {
            return Objects.hash(u, v);
        }
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int t = in.nextInt();
        for (int ii = 0; ii < t; ii++) {
            int n = in.nextInt();
            List<Integer>[] graph = new List[n + 1];
            for (int i = 0; i < n + 1; i++) {
                graph[i] = new ArrayList<>();
            }

            List<Edge> edges = new ArrayList<>();
            long[] edgeWeight = new long[n - 1];
            Map<Edge, Integer> edgeIndex = new HashMap<>();
            boolean[] visited = new boolean[n + 1];

            for (int i = 0; i < n - 1; i++) {
                int u = in.nextInt();
                int v = in.nextInt();
                graph[u].add(v);
                graph[v].add(u);

                Edge e = new Edge(min(u, v), max(u, v));
                edges.add(e);
                edgeIndex.put(e, i);
            }

            dfs(1, edges, edgeIndex, edgeWeight, graph, visited);
//            edges.sort((o1, o2) -> {
//                Integer ind1 = edgeIndex.get(o1);
//                Integer ind2 = edgeIndex.get(o2);
//                return Long.compare(edgeWeight[ind1], edgeWeight[ind2]);
//            });
            sortArray(edgeWeight);

            long res = 0;
            int m = in.nextInt();
            long[] p = readLongArray(m, in);
            sortArray(p);
            int j = p.length - 1;
            long k = 1;
            while (j > n - 2) {
                k = k * p[j] % MOD;
                j--;
            }
            for (int i = edgeWeight.length - 1; i >= 0; i--) {
                long kk = k;
                if (j >= 0) {
                    kk = kk * p[j] % MOD;
                }

                res = (res + (edgeWeight[i] * kk % MOD)) % MOD;

                k = 1;
                j--;
            }
            out.println(res);
        }



        out.close();
    }

    static void sortArray(long[] a) {
        Random random = new Random();

        for (int i = 0; i < a.length; i++) {
            int randomPos = random.nextInt(a.length);
            long t = a[i];
            a[i] = a[randomPos];
            a[randomPos] = t;
        }
        Arrays.sort(a);
    }

    private static long dfs(int v, List<Edge> edges, Map<Edge, Integer> edgeIndex, long[] edgeWeight, List<Integer>[] graph, boolean[] visited) {
        visited[v] = true;

        long res = 0;
        for (Integer u : graph[v]) {
            if (!visited[u]) {
                Edge edge = new Edge(min(u, v), max(u, v));
                long down = dfs(u, edges, edgeIndex, edgeWeight, graph, visited);
                edgeWeight[edgeIndex.get(edge)] = (down + 1) * (graph.length - 1 - down - 1);
                res += down + 1;
            }
        }
        return res;
    }


    private static void outputArray(List<Integer> ans, PrintWriter out) {
        StringBuilder str = new StringBuilder();
        for (int an : ans) {
            str.append(an).append(" ");
        }
        out.println(str);
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }
    }
}