#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int c, T, n, k;
int u[N], v[N], vis[N];
vector<int> G[N], eG[N];
set<pair<int, int>> s;
set<set<pair<int, int>>> ss;
void dfs(int u){
	vis[u] = 1;
	for(int v: eG[u]){
		if(vis[v]) continue;
		pair<int, int> tmp{min(u, v), max(u, v)};
		s.insert(tmp);
		if((int)s.size() == n - 2) ss.insert(s);
		dfs(v);
		s.erase(tmp);
	}
	vis[u] = 0;
}
signed main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cin.tie(nullptr) -> sync_with_stdio(false);
	for(cin >> c >> T; T --> 0;){
		cin >> n >> k;
		for(int i=1; i<=n; i++) G[i].clear();
		for(int i=1; i<n; i++) eG[i].clear(); 
		ss.clear();
		for(int i=1; i<n; i++){
			cin >> u[i] >> v[i];
			G[u[i]].push_back(i);
			G[v[i]].push_back(i);
		}
		if(c == 18){cout << "1\n"; continue;}
		for(int i=1; i<n; i++){
			for(int j: G[u[i]]) if(j != i) eG[i].push_back(j);
			for(int j: G[v[i]]) if(j != i) eG[i].push_back(j);
		}
		while(k --> 0){
			int x; cin >> x;
			s.clear(); dfs(x);
		}
		cout << ss.size() << "\n";
	}
	return 0;
}
/*
1 1
5 1
1 2
1 3
1 4
1 5
1
*/
