#include<bits/stdc++.h>
#define coin const int
#define ull unsigned long long
#define ll long long
#define int ll

using namespace std;
const int N = 100000 + 10;
const int inf = 998244353;

int read () {
	int x = 0, k = 1; char c = 0;
	while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); }
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
	return x * k;
}

using Pii = pair<int, int>;
int c, T;
int n, k;
int u, v;
int e[N];
vector<int> G[N]; 
unordered_set<int> ret;

int Hsh (vector<Pii> &E) {
	int mod = 1e9 + 7, bse = 131, qret = 0;
	for (Pii P: E) qret = (qret * bse % mod + ((P.first << 1) ^ P.second)) % mod;
	return qret;
}

void dfs (int u, int p, unordered_set<int> S, vector<Pii> q) {
	if (S.size() == n) return ret.insert(Hsh(q)), void();
	for (int v: G[u]) if (!S.count(v)) S.insert(v), q.push_back(Pii(u, v)), dfs(v, u, S, q), q.pop_back(), S.erase(v);
	for (int v: G[p]) if (!S.count(v)) S.insert(v), q.push_back(Pii(p, v)), dfs(v, p, S, q), q.pop_back(), S.erase(v);
} 

void work () {
	n = read(), k = read(), ret.clear(); unordered_set<int> TMP; vector<Pii> TMP2;
	for (int i = 1; i <= n; ++i) G[i].clear();
	for (int i = 1; i < n; ++i) u = read(), v = read(), G[u].push_back(v), G[v].push_back(u);
	for (int i = 1; i <= k; ++i) e[i] = read();
	for (int i = 1; i <= k; ++i) TMP.insert(e[i]), dfs(e[i], 0, TMP, TMP2), TMP.erase(e[i]);
	cout << ret.size() << endl;
}

signed main () {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	c = read(), T = read();
	while (T--) work();
	return 0;
}

/*
1 1
4 1
1 2
2 3
2 4
1
*/

