#include<bits/stdc++.h>
using namespace std;
namespace IO{
	template<class T> inline void read(T &x){
		char ch=getchar(),fushu=0; x=0;
		while(ch<'0'||ch>'9'){
			if(ch=='-')fushu=1;
			ch=getchar();
		}
		while(ch>='0'&&ch<='9')x=x*10+(ch^48),ch=getchar();
		if(fushu)x=-x;
	}
	char p[205];
	template<class T> inline void write(T x){
		if(x<0)putchar('-'),x=-x;
		if(!x)putchar('0');
		int t=0;
		while(x)p[++t]=(x%10)^48,x/=10;
		while(t)putchar(p[t--]);
	}
}
using IO::read;
using IO::write;
#define ll long long
#define ull unsigned long long
#define ld long double
#define it128 __int128
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fd(i,r,l) for(int i=(r);i>=(l);--i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
const int N=1e5+5;
const int mod=1e9+7;
int cid,T,n,K;
int U[N],V[N];
vector<int> g[N];
int fac[N];
int f[N];
void dfs(int x,int y){
	f[x]=1;
	int son=0;
	for(int v:g[x]){
		if(v==y)continue;
		son++;
		dfs(v,x);
		f[x]=(ll)f[x]*f[v]%mod;
	}
	f[x]=(ll)f[x]*fac[son]%mod;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	read(cid),read(T);
	while(T--){
		read(n),read(K);
		fac[0]=1;
		fo(i,1,n){
			fac[i]=fac[i-1]*(ll)i%mod;
			g[i].clear();
		}
		fo(i,1,n-1){
			int u,v;
			read(u),read(v);
			U[i]=u,V[i]=v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		int ans=0;
		fo(i,1,K){
			int e;
			read(e);
			dfs(U[e],V[e]);
			dfs(V[e],U[e]);
			ans=(ans+(ll)f[U[e]]*f[V[e]]%mod)%mod;
		}
		write(ans),putchar('\n');
	}
	return 0;
}

