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

typedef long long i64;

const int SIZE = 1e5+5;
const int MOD = 1e9+7;

i64 n, k, b, ans;
vector<int> g[SIZE];
pair<int,int> qwq[SIZE];
i64 sc[SIZE];
bool tag[SIZE];

bool in(int u, int v) {
	return qwq[u].first == qwq[v].first || qwq[u].second == qwq[v].second || qwq[u].first == qwq[v].second || qwq[v].first == qwq[u].second;
}

void dfs(i64 u, i64 fr) {
	tag[u] = true;
	for (i64 i = 1; i < n; ++i) {
		if (!tag[i] && u != i && fr != i && in(u, i)) {
			if (u == b) {
				++ans;
				ans %= MOD;
			}
			dfs(i, u);
		}
	}
	tag[u] = false;
}

void solve1() {
	ans = 0;
	scanf("%lld%lld",&n,&k);
	for (int i = 1; i <= n; ++i) {
		tag[i] = false;
		vector<int>().swap(g[i]);
	}
	for (int i = 1; i < n; ++i) {
		i64 u, v;
		scanf("%lld%lld",&u,&v);
		if (u > v) swap(u, v);
		qwq[i] = make_pair(u, v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 1; i <= k; ++i) scanf("%lld",&b);
	if (k != 1) puts("2");
	dfs(b, 0);
	printf("%lld\n",ans);
}

int main() {
	#ifdef fio
	freopen("../test.in","r",stdin);
	#else
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	#endif
	int c, t;
	scanf("%d%d",&c,&t);
	while (t--) {
		solve1();
	}
	return 0;
}
