#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

struct node{
	int ui, vi;
};

int c, T, n, k, ei;
int ans = 0;
bool vis[maxn];
node edge[maxn]; 
vector<int>linked[maxn];

void dfs(int x, int cnt){
	vis[x] = true;
	if(cnt == n - 2){
		ans ++;
		ans = ans % mod;
		vis[x] = false;
		return; 
	}
	for(auto i : linked[edge[x].ui]){
		if(!vis[i]){
			dfs(i, cnt + 1);
		}
	}
	for(auto i : linked[edge[x].vi]){
		if(!vis[i]){
			dfs(i, cnt + 1);
		}
	}
	vis[x] = false;
	return;
}

void solve(){
	ans = 0;
	for(int i = 1; i <= n; i++){
		linked[i].clear();
	}
	cin >> n >> k;
	for(int i = 1; i < n; i++){
		cin >> edge[i].ui >> edge[i].vi;
		linked[edge[i].ui].push_back(i);
		linked[edge[i].vi].push_back(i);
	}
	for(int i = 1; i <= k; i++){
		cin >> ei;
		dfs(ei, 1);
	}
	cout << ans << endl;
	return;
}

int main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin >> c >> T;
	while(T--){
		solve();
	}
	return 0;
}
