#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9+7;
const int N = 1e5+10;
int n,k;
vector<int> g[N];
ll Qpow(ll a,int x){
	ll r=1;
	for(;x;x>>=1,a=a*a%MOD)if(x&1)
		r=r*a%MOD;
	return r;
}
void work2(){
	if(n==2)printf("1\n");
	else printf("%lld\n", Qpow(n-1,n-3));
}
struct edge{
	int u,v;
}e[N],ee[N];
int fa[N];
int getfa(int x){
	if(fa[x]==x)return x;
	return fa[x]=getfa(fa[x]);
}
bool merge(int u,int v){
	int fu=getfa(u),fv=getfa(v);
	if(fu==fv)return false;
	fa[fu]=fv;
	return true;
}
int a[N];
void work1(){
	for(int i=1;i<n;i++)
		scanf("%d%d", &e[i].u, &e[i].v);
	int m=0;
	for(int i=1;i<=k;i++)scanf("%d", a+i);
	for(int i=1;i<=n-1;i++)
		for(int j=i+1;j<=n-1;j++){
			if(e[i].u==e[j].u||e[i].v==e[j].v||e[i].u==e[j].v||e[i].v==e[j].u){
				m++;
				ee[m].u=i,ee[m].v=j;
			}
		}
	int ans=0;
	for(int x=1;x<=k;x++){
		bool bz[n];
		for(int s=0;s<(1<<m);s++){
			for(int i=1;i<n;i++)fa[i]=i;
			for(int i=1;i<n;i++)bz[i]=false;
			bool flag=true;
			for(int i=1;i<=m;i++)if(s&(1<<(i-1))){
				bz[ee[i].u]=bz[ee[i].v]=true;
				flag&=merge(ee[i].u,ee[i].v);
			}
			for(int i=1;i<n;i++)if(!bz[i])continue;
			if(!bz[x]||!flag)continue;
			int tot=0;
			for(int i=1;i<n;i++)if(bz[i])tot++;
			if(__builtin_popcount(s)!=tot-1)continue;
			ans++;
		}
	}
	printf("%d\n", ans);
}
void work(){
	scanf("%d%d", &n, &k);
	work1();
	//work2();
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int id, T;
	scanf("%d%d", &id, &T);
	while(T--)work();
	return 0;
}

