#include <bits/stdc++.h>
using namespace std;
int id, t, n, k, p, x, y, ans, ci, h[100010], a[100010], jc[100010], vis[100010], du[100010], f[100010];
struct node{
	int x, y, z, next;
}d[200010];
struct edge{
	int x, y;
}b[100010];
inline int read(){
	int s=0, w=1; char ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-') w=-1; ch=getchar();
	}
	while (ch>='0' && ch<='9'){
		s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
	}
	return s*w;
}
const int mo = 1e9 + 7;
void add(int x, int y, int z){
	d[++p].y = y, d[p].z = z, d[p].next = h[x], h[x] = p;
}
void dfs(int x, int fa){
	for (int i=h[x]; i; i=d[i].next){
		int y = d[i].y;
		if (y == fa) continue;
		du[x] ++;
		dfs(y, x);
	}
}
int dfs2(int x, int fa){
	int ret = 0;
	for (int i=h[x]; i; i=d[i].next){
		int y = d[i].y;
		if (y == fa) continue;
		du[x] ++;
		ret |= dfs2(y, x);
		if (d[i].z == a[1]) ret = 1;
	}
	if (ret) du[x] --;
	return ret;
}
int main(){
	freopen ("traverse.in", "r", stdin);
	freopen ("traverse.out", "w", stdout);
	id=read(), t=read();
	jc[0] = 1;
	for (int i=1; i<=100000; i++) jc[i] = 1LL * jc[i-1] * i % mo;
	while (t --){
		n=read(), k=read();
		for (int i=1; i<=n; i++) h[i] = du[i] = vis[i] = 0;
		p = 0;
		for (int i=1; i<n; i++){
			x=read(), y=read();
			b[i] = (edge){x, y};
			add(x, y, i); add(y, x, i);
		}
		for (int i=1; i<=k; i++){
			a[i]=read();
			vis[a[i]] = 1;
		}
		if (id == 18){
			puts ("1");
			continue;
		}
		if (id >= 19 && id <= 21){
			if (n == 2){
				puts ("1");
				continue;
			}
			if (k >= 2) ans = 1LL*(1LL*k*(k-1)/2LL)%mo*jc[n-3]%mo;
			ans = (ans + 1LL*k*(n-1-k)%mo*jc[n-3]%mo)%mo;
			printf ("%d\n", ans);
			continue;
		}
		if (k == 1){
			dfs(b[a[k]].y, b[a[k]].x);
			dfs(b[a[k]].x, b[a[k]].y);
			ans = 1;
			for (int i=1; i<=n; i++){
				ans = 1LL * ans * jc[du[i]] % mo;
			}
			printf ("%d\n", ans);
			continue;
		}
		if (k == 2){
			dfs(b[a[1]].y, b[a[1]].x);
			dfs(b[a[1]].x, b[a[1]].y);
			ans = 1;
			for (int i=1; i<=n; i++){
				ans = 1LL * ans * jc[du[i]] % mo;
			}
			for (int i=1; i<=n; i++) du[i] = 0;
			dfs(b[a[2]].y, b[a[2]].x);
			dfs(b[a[2]].x, b[a[2]].y);
			int ans2 = 1;
			for (int i=1; i<=n; i++){
				ans2 = 1LL * ans2 * jc[du[i]] % mo;
			}
			for (int i=1; i<=n; i++) du[i] = 0;
			int tmp = dfs2(b[a[2]].y, b[a[2]].x);
			tmp = dfs2(b[a[2]].x, b[a[2]].y);
			int del = 1;
			for (int i=1; i<=n; i++){
				del = 1LL * del * jc[du[i]] % mo;
			}
			ans2 = (ans2 - del + mo) % mo;
			printf ("%d\n", (ans + ans2) % mo);
		}
	}
	return 0;
}
