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.
#include <bits/stdc++.h>
using namespace std;
struct edge {
  int t, f, w;
  bool operator<(const edge& e) const { return w > e.w; }
  edge(int from, int to, int weight) {
    t = to;
    f = from;
    w = weight;
  }
};
const double EPS = (1e-9);
class UnionFind {
 public:
  vector<int> p, rank, setSize;
  int numSets;
  UnionFind(int N) {
    setSize.assign(N, 1);
    numSets = N;
    rank.assign(N, 0);
    p.assign(N, 0);
    for (int i = 0; i < N; i++) p[i] = i;
  }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) {
    if (!isSameSet(i, j)) {
      numSets--;
      int x = findSet(i), y = findSet(j);
      if (rank[x] > rank[y]) {
        p[y] = x;
        setSize[x] += setSize[y];
      } else {
        p[x] = y;
        setSize[y] += setSize[x];
        if (rank[x] == rank[y]) rank[y]++;
      }
    }
  }
  int numDisjointSets() { return numSets; }
  int sizeOfSet(int i) { return setSize[findSet(i)]; }
};
long long root(long long x) {
  long long l = 0, r = 1e9 + 1;
  while (l < r - 1) {
    long long m = (l + r) / 2;
    if (m * m > x)
      r = m;
    else
      l = m;
  }
  return l;
}
struct line {
  double a, b, c;
};
bool areParallel(line l1, line l2) {
  return (fabs(l1.a - l2.a) < EPS) && (fabs(l1.b - l2.b) < EPS);
}
bool areSame(line l1, line l2) {
  return areParallel(l1, l2) && (fabs(l1.c - l2.c) < EPS);
}
struct point {
  double x, y;
  point() { x = y = 0.0; }
  point(double _x, double _y) : x(_x), y(_y) {}
  bool operator<(point other) const {
    if (fabs(x - other.x) > EPS) return x < other.x;
    return y < other.y;
  }
};
void pointsToLine(point p1, point p2, line& l) {
  if (fabs(p1.x - p2.x) < EPS) {
    l.a = 1.0;
    l.b = 0.0;
    l.c = -p1.x;
  } else {
    l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x);
    l.b = 1.0;
    l.c = -(double)(l.a * p1.x) - p1.y;
  }
}
bool areIntersect(line l1, line l2, point& p) {
  if (areParallel(l1, l2)) return false;
  p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);
  if (fabs(l1.b) > EPS)
    p.y = -(l1.a * p.x + l1.c);
  else
    p.y = -(l2.a * p.x + l2.c);
  return true;
}
long long binpowmod(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int findXOR(int n) {
  switch (n % 4) {
    case 0:
      return n;
    case 1:
      return 1;
    case 2:
      return n + 1;
    case 3:
      return 0;
  }
}
int rangeXOR(int l, int r) { return (findXOR(l - 1) ^ findXOR(r)); }
int getbit(int mask, int bit) { return (mask & (1 << bit)); }
void setbit(int& mask, int bit, int val) {
  if (val)
    mask |= (1 << bit);
  else
    mask &= ~(1 << bit);
}
const int N = 1e5 + 1;
const long long INF = 1e7 + 100;
const int MOD = 1e9 + 7;
class SegmentTree {
 private:
  vector<pair<int, int>> st;
  vector<int> lp;
  vector<int> A;
  int n;
  int left(int p) { return p << 1; }
  int right(int p) { return (p << 1) + 1; }
  pair<int, int> merge(pair<int, int> p1, pair<int, int> p2) {
    if (p1.first == p2.first) return {p1.first, p1.second + p2.second};
    if (p1.first < p2.first) return p1;
    return p2;
  }
  void build(int p, int L, int R) {
    if (L == R) {
      st[p] = {A[L], 1};
    } else {
      build(left(p), L, (L + R) / 2);
      build(right(p), (L + R) / 2 + 1, R);
      pair<int, int> p1 = st[left(p)], p2 = st[right(p)];
      st[p] = merge(p1, p2);
    }
  }
  pair<int, int> rmq(int p, int L, int R, int i, int j) {
    if (i > R || j < L) return {-1, -1};
    if (L >= i && R <= j) return st[p];
    pair<int, int> p1 = rmq(left(p), L, (L + R) / 2, i, j);
    pair<int, int> p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);
    if (p1.first == -1) return p2;
    if (p2.first == -1) return p1;
    return merge(p1, p2);
  }
  void update_point(int p, int L, int R, int idx, int v) {
    int i = idx, j = idx;
    if (i > R || j < L) return;
    if (L == i && R == j) {
      A[L] = v;
      st[p] = {v, 1};
      return;
    }
    pair<int, int> p1, p2;
    update_point(left(p), L, (L + R) / 2, idx, v);
    update_point(right(p), (L + R) / 2 + 1, R, idx, v);
    p1 = st[left(p)];
    p2 = st[right(p)];
    st[p] = merge(p1, p2);
  }

 public:
  SegmentTree(const vector<int>& _A) {
    A = _A;
    n = (int)A.size();
    st.assign(4 * n, {0, 0});
    lp.assign(4 * n, 0);
    build(1, 0, n - 1);
  }
  pair<int, int> rmq(int i, int j) { return rmq(1, 0, n - 1, i, j); }
  void update_point(int idx, int new_value) {
    update_point(1, 0, n - 1, idx, new_value);
  }
};
vector<vector<pair<int, int>>> adj;
vector<bool> visited;
vector<long long> children;
priority_queue<long long> pq;
int n;
int dfs(int u) {
  visited[u] = true;
  int ret = 1;
  for (pair<int, int> x : adj[u]) {
    if (!visited[x.first]) {
      ret += dfs(x.first);
      pq.push(1ll * children[x.first] * (n - children[x.first]));
    }
  }
  return children[u] = ret;
}
void solve() {
  cin >> n;
  adj.assign(n, vector<pair<int, int>>());
  visited.assign(n, false);
  children.assign(n, 0);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back({v, i});
    adj[v].push_back({u, i});
  }
  dfs(0);
  int m;
  cin >> m;
  vector<long long> v;
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.rbegin(), v.rend());
  long long init = 1;
  int i = 0;
  if (m > n - 1) {
    int need = m - (n - 1);
    while (need--) {
      init = (init * v[i]) % MOD;
      i++;
    }
  }
  long long ans = 0;
  for (; i < int(v.size()); ++i) {
    init = (init * v[i]) % MOD;
    long long add = (init * pq.top());
    pq.pop();
    ans = (ans + add) % MOD;
    init = 1;
  }
  while (!pq.empty()) {
    ans = (ans + pq.top()) % MOD;
    pq.pop();
  }
  cout << ans << '\n';
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    solve();
  }
}
