#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second

using namespace std;
using ll = long long;
using pii = pair<int, int>;

void SetIO(string s = "")
{
    if (s != "")
    {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);
}

const int N = 2e5 + 5;
const ll MOD = 1e9 + 7;
ll add(ll x, ll y){return (x += y) >= MOD && (x -= MOD), x;}
void Add(ll& x, ll y){x = add(x, y);}
ll sub(ll x, ll y){return (x -= y) < 0 && (x += MOD), x;}
void Sub(ll& x, ll y){x = sub(x, y);}
ll Pow(ll x, ll y)
{
    ll res = 1;
    for (; y; x = x * x % MOD, y >>= 1)if (y & 1)
        res = res * x % MOD;
    return res;
}

int ID, T, n, m, a[N], g[N];
ll ans, f[N], fac[N], ifac[N];
vector<int> edge[N];
bool bj[N];

ll A(int n, int m){return fac[n] * ifac[n - m] % MOD;}
void Dfs(int, int);

signed main()
{
    SetIO("traverse");
    cin >> ID >> T;
    while(T--)
    {
        ans = 0;
        cin >> n >> m;
        fill(bj, bj + 2 * n + 1, false);
        for (int i = 1; i <= 2 * n; i++)
            edge[i].clear();
        fac[0] = ifac[0] = 1;
        for (int i = 1; i <= n; i++)
        {
            fac[i] = fac[i - 1] * i % MOD;
            ifac[i] = Pow(fac[i], MOD - 2);
        }
        for (int i = 1, u, v; i < n; i++)
        {
            cin >> u >> v;
            edge[i].eb(u + n);
            edge[i].eb(v + n);
            edge[u + n].eb(i);
            edge[v + n].eb(i);
        }
        for (int i = 1; i <= m; i++)
        {
            cin >> a[i];
            Dfs(a[i], 0);
            Add(ans, f[a[i]]);
            bj[a[i]] = true;
        }
        cout << ans << '\n';
    }
}

void Dfs(int u, int fa)
{
    f[u] = 1;
    int num = 0, have = 0;
    bool flag = false;
    for (int v : edge[u])if (v != fa)
    {
        Dfs(v, u);
        num++;
        if (bj[v])
            have++;
        f[u] = f[u] * f[v] % MOD;
    }
    if (!num)
        return;
    if (u > n)
    {
        if (num == have)
            f[u] = 0;
        else
            f[u] = f[u] * A(num - 1, have) % MOD * fac[num - have] % MOD;
    }
}