#include <bits/stdc++.h>
#define int long long
#define N 100005
using namespace std;
int n, k, e[N], ans;
int head0[N], to0[N << 1], nxt0[N << 1], tot0;
int head[N], to[N << 1], nxt[N << 1], tot;

inline int read() {
	int x = 0, m = 1;
	char ch = 0;
	while (!isdigit(ch)) {
		if (ch == '-') m = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return x * m;
}

inline void add0(int u, int v) {
	to0[tot0] = v;
	nxt0[tot0] = head0[u];
	head0[u] = tot0++;
	return ;
}

inline void add(int u, int v) {
	to[tot] = v;
	nxt[tot] = head[u];
	head[u] = tot++;
	return ;
}

void dfs(int x, int f, int pre) {
	for (int i = head0[x]; ~i; i = nxt0[i]) {
		if (to0[i] == f) continue;
		if (f) {
			add(pre, (i >> 1) + 1);
		}
		dfs(to0[i], x, (i >> 1) + 1);
		for (int l = head0[x]; ~l; l = nxt0[l]) {
			if ((i >> 1) + 1 == (l >> 1) + 1) continue;
			add((i >> 1) + 1, (l >> 1) + 1);
		}
	}
	return ;
}

bool vis[N];
inline int work(int x) {
	int res = 0;
	for (int i = head[x]; ~i; i = nxt[i]) {
		if (vis[to[i]]) continue;
		vis[to[i]] = 1;
		res += work(to[i]);
		vis[to[i]] = 0;
	}
	return res ? res : 1;
}

signed main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int c = read(), T = read();
	while (T--) {
		if (c == 18) {
			printf("1\n");
			continue;
		}
		memset(head, -1, sizeof head);
		memset(head0, -1, sizeof head0);
		n = read(), k = read();
		for (int i = 1; i < n; i++) {
			int u = read(), v = read();
			add0(u, v), add0(v, u);
		}
		dfs(1, 0, 0);
		for (int i = 1; i <= k; i++) {
			e[i] = read();
			vis[e[i]] = 1;
			ans += work(e[i]);
			vis[e[i]] = 0;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

