#include<iostream>
#include<vector>
using namespace std;

struct EDGE
{
	long long v, w;
};
struct NODE
{
	long long u, v;
};
NODE edge[200010];
vector<EDGE> G[200010];
long long fa[200010];
bool f[200010];
bool g[200010];
long long fac[200010];
bool fl[200010];
const long long mod = 1e9 + 7;
long long c, T, n, k; 

void dfs(long long u)
{
	for(long long i = 0; i < G[u].size(); i++)
	{
		long long v = G[u][i].v, w = G[u][i].w;
		if(v != fa[u])
		{
			if(w) f[u] = 1;
			fa[v] = u;
			dfs(v);
		}
	}
	for(long long i = 0; i < G[u].size(); i++)
	{
		long long v = G[u][i].v, w = G[u][i].w;
		if(v != fa[u])
		{
			if(!w && f[v])
			{
				G[u][i].w = 1;
				f[u] = 1;
			}	
		}
	}
}

void dfs2(long long u)
{
	for(long long i = 0; i < G[u].size(); i++)
	{
		long long v = G[u][i].v, w = G[u][i].w;
		if(v == fa[u])
		{
			g[u] |= w;
		}
	}
	if(g[u]) 
	{
		for(long long i = 0; i < G[u].size(); i++)
		{
			long long v = G[u][i].v, w = G[u][i].w;
			if(v != fa[u])
			{
				g[v] = 1;
			}
			else
			{
				G[u][i].w = 1;
			}
		}
	}
	else
	{
		long long cnt = 0;
		for(long long i = 1; i <= G[u].size(); i++)
		{
			if(G[u][i].w) cnt++;
		}
		if(cnt >= 2)
		{
			for(long long i = 1; i <= G[u].size(); i++)
			{
				long long v = G[u][i].v, w = G[u][i].w;
				if(v != fa[u])
				{
					g[v] = 1;
				}
			}
		}
		else if(cnt == 1)
		{
			for(long long i = 1; i <= G[u].size(); i++)
			{
				long long v = G[u][i].v, w = G[u][i].w;
				if(v != fa[u] && !G[u][i].w)
				{
					g[v] = 1;
				}
			}
		}
	}
	for(long long i = 0; i < G[u].size(); i++)
	{
		long long v = G[u][i].v, w = G[u][i].w;
		if(v != fa[u])
		{
			dfs2(v);
		}
	}
}

int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	scanf("%lld%lld", &c, &T);
	fac[0] = 1;
	for(long long i = 1; i <= 200000; i++) fac[i] = fac[i - 1] * i % mod;
	while(T--)
	{
		memset(f, 0, sizeof f);
		memset(g, 0, sizeof g);
		scanf("%lld%lld", &n, &k);
		for(long long i = 1; i < n; i++)
		{
			scanf("%lld%lld", &edge[i].u, &edge[i].v);
		}
		for(long long i = 1; i <= k; i++)
		{
			int xxx;
			scanf("%lld", &xxx);
			fl[xxx] = 1;
		}
		for(long long i = 1; i < n; i++)
		{
			G[edge[i].u].push_back({edge[i].v, fl[i]});
			G[edge[i].v].push_back({edge[i].u, fl[i]});
		}
		dfs(1);
		dfs2(1);
//		for(int i = 1; i <= n; i++) printf("%d ", f[i]);
//		printf("\n");
//		for(int i = 1; i <= n; i++) printf("%d ", g[i]);
//		printf("\n");
		
		long long ans = 1;
		for(long long u = 1; u <= n; u++)
		{
			long long siz = G[u].size(), cnt = 0;
			for(long long i = 0; i < siz; i++)
			{
				long long v = G[u][i].v, w = G[u][i].w;
				cnt += w;
			}
//			printf("%d %d\n", siz, cnt);
			ans = ans * (cnt * fac[siz - 1] % mod - (cnt * (cnt - 1) / 2) % mod * fac[siz - 2] % mod) % mod;
//			printf("asdsd %d\n", ans);
		}
		printf("%lld\n", ans);
	}
	return 0;
}
