func_code_string: #include <bits/stdc++.h>   using namespace std;   long long const lim = 1e5 + 5;   long long const mod = 1000000007;   vector<long long> adj[lim + 5];   long long vis[lim + 5], n;   vector<long long> count_edge;   long long child[lim + 5];   void all_clear() {     count_edge.clear();     for (long long i = 1; i <= lim; i++) {       adj[i].clear();       vis[i] = -1;       child[i] = 0;     }   }   void dfs(long long s) {     vis[s] = 1;     for (auto v : adj[s]) {       if (vis[v] == -1) {         dfs(v);         child[s] += child[v];         count_edge.push_back(child[v] * (n - child[v]));       }     }     child[s] += 1;   }   void solve() {     cin >> n;     all_clear();     for (int i = 1; i < n; i++) {       long long a, b;       cin >> a >> b;       adj[a].push_back(b), adj[b].push_back(a);     }     long long m;     cin >> m;     vector<long long> fact;     for (int i = 0; i < m; i++) {       long long p;       cin >> p;       fact.push_back(p);     }     dfs(1);     sort(count_edge.rbegin(), count_edge.rend());     sort(fact.rbegin(), fact.rend());     for (int i = 0; i < count_edge.size(); i++) count_edge[i] %= mod;     long long ans = 0;     if (fact.size() > count_edge.size()) {       while (fact.size() > count_edge.size()) {         long long val = fact[0];         fact.erase(fact.begin());         fact[0] = (fact[0] * val) % mod;       }       for (int i = 0; i < fact.size(); i++) {         ans = (ans + (fact[i] * count_edge[i]) % mod) % mod;       }     } else {       for (int i = 0; i < count_edge.size(); i++) {         if (i >= fact.size()) {           ans = (ans + count_edge[i]) % mod;         } else {           ans = (ans + (fact[i] * count_edge[i]) % mod) % mod;         }       }     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int t = 1, no = 0;     cin >> t;     while (t--) {       solve();     }     return 0;   }   