#include<bits/stdc++.h>
namespace C {
	const int N = 1e5 + 5, K = 1e5 + 5, Mod = 1e9 + 7;
	template<typename T>
	inline T mod(const T value) {
		return value % Mod;
	}
	int c, t, n, k, e[K];
	struct Edge {
		int from, to, id;
	} *edge;
	struct Point {
		std::vector<int> children;
		int count;
	} *point;
	bool vis[N];
	int dfs(const int now) {
		vis[now] = true;
		if (point[edge[now].from].count <= 0 && point[edge[now].to].count <= 0) {
			return 1;
		}
		long long ans = 0;
		for (int i : point[edge[now].from].children) {
			if (!vis[i]) {
				point[edge[i].from].count--;
				point[edge[i].to].count--;
				ans = mod(ans + dfs(i));
				point[edge[i].from].count++;
				point[edge[i].to].count++;
			}
		}
		for (int i : point[edge[now].to].children) {
			if (!vis[i]) {
				point[edge[i].from].count--;
				point[edge[i].to].count--;
				ans = mod(ans + dfs(i));
				point[edge[i].from].count++;
				point[edge[i].to].count++;
			}
		}
		vis[now] = false;
		return ans;
	}
	int main() {
		std::freopen("traverse.in", "r", stdin);
		std::freopen("traverse.out", "w", stdout);
		std::ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		std::cout.tie(nullptr);
		for (std::cin >> c >> t; t; t--) {
			std::cin >> n >> k;
			edge = new Edge[(n + 5) << 1];
			point = new Point[n + 5];
			for (int i = 1; i < n; i++) {
				int u, v;
				std::cin >> u >> v;
				edge[(i << 1) - 1] = {u, v, i};
				edge[(i << 1)] = {v, u, i};
				point[u].children.push_back((i << 1) - 1);
				point[u].count++;
				point[v].children.push_back(i << 1);
				point[v].count++;
			}
			for (int i = 0; i < k; i++) {
				std::cin >> e[i];
			}
			int ans = 0;
			for (int i = 0; i < k; i++) {
				ans = mod(ans + dfs(e[i]));
			}
			std::cout << ans << "\n";
			delete[] edge;
			delete[] point;
		}
		return 0;
	}
}
int main()
{
	return C::main(); 
}

