#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; i ++)
#define per(i, r, l) for (int i = r; i >= l; i --)
using namespace std;
const int _ = 1e5 + 5;
int c, T, n, k;
int ux[_], uy[_], vis[_], ans;
void dfs (int x, int st) {
//	vis[x] = 1;
//cout << x << ' ' << st << '\n';
	if (st == n - 1) ans ++;
	rep(i, 1, n - 1) {
		if (i == x) continue ;
		if (ux[x] == uy[i] || ux[x] == ux[i] || uy[x] == uy[i] || uy[x] == ux[i]) {
			if (vis[i]) continue ;
			vis[i] = 1;
//			cout << x << ' ' << i << '\n';
				dfs(i, st + 1);
			vis[i] = 0;
		}
	}
}
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cin >> c >> T;
	while (T --) {
		cin >> n >> k;
		rep(i, 1, n - 1) {
			cin >> ux[i] >> uy[i];
			vis[i] = 0;
		}
		vector <int> a(k + 1);
		ans = 0;
		rep(i, 1, k) cin >> a[i];
		rep(i, 1, k) {
			rep(i, 1, n - 1) vis[i] = 0;
			vis[a[i]] = 1;
			dfs(a[i], 1);
		}
		cout << ans << '\n';
	} 
	
	return 0;
}
/*
1 1
4 1
1 2
2 3
2 4
1

*/
