#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 10;

int n, k, ans;
int c[N], d[N];
vector<pii> g[N];
vector<int> g1[N];
bool vis[N];

void dfs(int u)
{
	vis[u] = true;
	for (int i = 0; i < g1[u].size(); i++)
	{
		int v = g1[u][i];
		if (vis[v])
			continue;
		ans++;
		dfs(v);
	}
	vis[u] = false;
}

int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cin.sync_with_stdio(false);
	
	int c, T;
	cin >> c >> T;
	
	if (1 <= c && c <= 3)
	{
		while (T--)
		{
			cin >> n >> k;
			
			for (int i = 1; i < n; i++)
			{
				int u, v;
				cin >> u >> v;
				g[u].push_back(make_pair(v, i));
			}
			
			for (int i = 1; i <= n; i++)
			{
				for (int j = 0; j < g[i].size(); j++)
					for (int k = 0; k < g[i].size(); k++)
						if (j != k)
						{
							int u = g[i][j].second;
							int v = g[i][k].second;
							g1[u].push_back(v);
							g1[v].push_back(u);
						}
			}
			
			for (int i = 1; i <= k; i++)
			{
				memset(vis, 0, sizeof(vis));
				int t;
				cin >> t;
				dfs(t);
			}
			
			cout << ans << endl;
		}
		return 0;
	}
	
	if (c == 18)
	{
		while (T--)
		{
			cin >> n >> k;
			for (int i = 1; i < n; i++)
			{
				int u, v;
				cin >> u >> v;
			}
			for (int i = 1; i <= k; i++)
			{
				int t;
				cin >> t;
			}
			cout << 1 << endl;
		}
		return 0;
	}
}

// 计数直接游戏结束 

 
