#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MaxN = 1e5 + 5;
const int Mod = 1e9 + 7;
LL Fac[MaxN], Inv[MaxN];
struct Link
{
	int Y, Next, Idx;
};
Link Graph[MaxN * 2];
int Nume, Head[MaxN];
void AddLink(int X, int Y, int Idx)
{
	Graph[++Nume] = {Y, Head[X], Idx};
    Head[X] = Nume;
}
int Subtask, T;
int N, K, X, Y, A[MaxN];
vector<int> G[MaxN];
void MakeInitial()
{
	Fac[0] = Inv[0] = Inv[1] = 1;
	for (int i = 2; i < MaxN; ++i)
	{
		Inv[i] = (Mod - Mod / i) * Inv[Mod % i] % Mod;
	}
	for (int i = 1; i < MaxN; ++i)
	{
		Fac[i] = Fac[i - 1] * i % Mod;
		Inv[i] = Inv[i - 1] * Inv[i] % Mod;
	}
}
void DFS1(int X, int Fa, int EX)
{
	int EY;
	for (int i = Head[X]; i; i = Graph[i].Next)
	{
		EY = Graph[i].Idx;
		if (EY != EX)
		{
			G[EX].push_back(EY);
		}
	}
	for (int i = Head[X]; i; i = Graph[i].Next)
	{
		if (Graph[i].Y != Fa)
		{
			DFS1(Graph[i].Y, X, Graph[i].Idx);
		}
	}
}
LL F[MaxN];
int Son[MaxN];
void DFS2(int X, int Fa)
{
	F[X] = A[X] ? 1 : 2;
	for (int Y : G[X])
	{
		if (Y != Fa)
		{
			DFS2(Y, X);
		    ++Son[X];
		}
	}
	for (int Y : G[X])
	{
		
	}
}
void DFS3(int X, int Fa)
{
	int Edges = Son[X] + (Fa != 0);
	LL Tmp = F[X] * Inv[Edges] % Mod * Fac[Edges - 1] % Mod;
	for (int Y : G[X])
	{
		if (Y != Fa)
		{
			DFS3(Y, X);
			F[Y] = Tmp * Fac[Son[Y] + 1] % Mod * Inv[Son[Y]] % Mod;
		}
	}
}
void Solve()
{
	Nume = 0;
	for (int i = 1; i < N; ++i)
	{
		G[i].clear();
	}
	for (int i = 1; i <= N; ++i)
	{
		A[i] = Head[i] = 0;
	}
	scanf("%d%d", &N, &K);
	for (int i = 1; i < N; ++i)
    {
    	scanf("%d%d", &X, &Y);
    	AddLink(X, Y, i);
    	AddLink(Y, X, i);
	}
    for (int i = 1; i <= K; ++i)
    {
    	scanf("%d", &X);
    	A[X] = 1;
	}
	DFS1(1, 0);
	DFS2(1, 0, 0);
	DFS3(0, 0);
	printf("%d\n", F[0]);
}
int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	scanf("%d", &T);
	MakeInitial();
	while (T--)
	{
		Solve();
	}
	return 0;
}
