#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 5;
int ans, n, q, rt;
bool f[maxn] = {0};
struct edges
{
	int l, r;
}e[maxn];

bool near(edges a, edges b)
{
	return (a.l == b.l || a.r == b.l || a.l == b.r || a.r == b.r);
}

bool pan()
{
	bool flag = 1;
	for(int i = 1; i < n; i ++)
		flag &= f[i];
	return flag;
}
vector<int> v;

void srh(int x,int fa)
{
	if(x == rt && pan())
	{
		ans ++;
		return ;
	}
	f[x] = 1;
	for(int y = 1; y < n; y++)
		if(x != y && y != fa && near(e[x], e[y]) && !f[y])
		{
			srh(y, x);
			printf("%d %d\n", x, y);
		}
	f[x] = 0;
}

void work()
{
	
	scanf("%d%d",&n, &q);
	for(int i = 1; i < n; i ++)
		scanf("%d%d", &e[i].l, &e[i].r);
	ans = 0;
	while(q--)
	{
		scanf("%d", &rt);
		srh(rt,0);
	}
	printf("%d\n", ans);
	return;
}

int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c, t;
	scanf("%d%d", &c, &t);
	while(t--)
	{
		if(c == 18)
			puts("1");
		else
			work();
	}
	return 0;
}
/*
7 1
5 2
1 2
1 3
2 4
2 5
1 3


*/
