func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5;   const int mod = 1e9 + 7;   int cnt;   int head[MAX + 5], to[4 * MAX + 5], nex[4 * MAX + 5];   void add(int u, int v) {     to[++cnt] = v;     nex[cnt] = head[u];     head[u] = cnt;   }   int n, m;   int _cnt;   long long prime[MAX + 5], es[MAX + 5];   int dfs(int u, int f) {     long long sub = 1;     for (int i = head[u]; i; i = nex[i]) {       if (to[i] != f) {         long long temp = dfs(to[i], u);         es[++_cnt] = temp * (n - temp);         sub += temp;       }     }     return sub;   }   bool cmp(long long a, long long b) { return a > b; }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       cnt = 0;       for (int i = 1; i <= n; i++) head[i] = 0;       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d %d , &u, &v);         add(u, v);         add(v, u);       }       scanf( %d , &m);       for (int i = 1; i <= m; i++) scanf( %lld , prime + i);       sort(prime + 1, prime + 1 + m);       if (m >= n) {         for (int i = n; i <= m; i++) prime[n - 1] = prime[n - 1] * prime[i] % mod;         m = n - 1;       }       _cnt = 0;       dfs(1, 0);       sort(es + 1, es + n, cmp);       long long ans = 0;       for (int i = 1; i < n; i++) {         if (m)           ans = (ans + es[i] * prime[m--] % mod) % mod;         else           ans = (ans + es[i]) % mod;       }       printf( %lld n , ans);     }     return 0;   }   