#include <bits/stdc++.h>
#define pii pair<int, int>
#define fir first
#define sec second
using namespace std;

const int N = 2e5 + 5;

int c, T, n, k, ans;
int a[N], vis[N];
vector<int> g[N];
struct edge{
	int u, v;
}e[N], e1[N];

void dfs(int u, int cnt){
	if (cnt == n - 2) return ans++, void();
	vis[u] = 1;
	for (auto v : g[u]){
		if (vis[v]) continue;
		dfs(v, cnt + 1);
	}
}

int main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cin >> c >> T;
	while (T--){
		cin >> n >> k;
		for (int i = 1; i <= n; i++) g[i].clear();
		for (int i = 1; i < n; i++){
			cin >> e1[i].u >> e1[i].v;
//			g[e1[i].u].push_back(e1[i].v);
//			g[e1[i].v].push_back(e1[i].u);
		}
		for (int i = 1; i < n; i++){
			for (int j = i + 1; j < n; j++){
				if (e1[i].u == e1[j].u || e1[i].v == e1[j].u || e1[i].u == e1[j].v || e1[i].v == e1[j].v) g[i].push_back(j), g[j].push_back(i);
			}
		}
		for (int i = 1; i <= k; i++) cin >> a[i];
		ans = 0;
		for (int i = 1; i <= k; i++){
			memset(vis, 0, sizeof(vis));
			dfs(a[i], 0);
		}
		cout << ans << endl;
	}
	return 0;
}

