#include<bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define MOD 1000000007
int n,k;
long long tc[MAXN],fc[MAXN];
struct edge{
	int v,id;
};
vector<edge>e[MAXN];
int d[MAXN];
bool fl[MAXN];
vector<pair<int,int> >es;
inline void build(int u,int v){
	e[u].emplace_back(edge{v,0});
	e[v].emplace_back(edge{u,0});
}
inline bool add(int u,int fa,int t,int w){
	if(u==t)return true;
	for(auto it:e[u])if(it.v!=fa&&!fl[it.id]){
		if(add(it.v,u,t,w)){
			d[u]+=w;
			return true;
		}
	}
	return false;
}
void solve(){
	cin>>n>>k;
	es.clear();
	for(int i=1;i<=n;++i)e[i].clear(),fl[i]=false,d[i]=0;
	for(int i=1,u,v;i<n;++i){
		cin>>u>>v;
		e[u].emplace_back(edge{v,i});
		e[v].emplace_back(edge{u,i});
		++d[u],++d[v];
		es.emplace_back(make_pair(u,v));
//		cerr<<'!'<<u<<' '
	}
	for(int i=1,j;i<=k;++i){
		cin>>j;
		fl[j]=true;
	}
	long long ans1=1;
	for(int i=1;i<=n;++i)ans1=ans1*fc[d[i]-1]%MOD;
	if(k==1){
		cout<<ans1<<'\n';
		return;
	}
	else if(k==2){
		ans1=2ll*ans1%MOD;
		long long ans2=1;
		vector<pair<int,int> >t;
		for(int i=1;i<n;++i)if(fl[i])t.emplace_back(es[i-1]);
//		int tot=n;
		e[n+1].clear(),e[n+2].clear();
		build(n+1,t[0].first);
		build(n+1,t[0].second);
		build(n+2,t[1].first);
		build(n+2,t[1].second);
		add(n+1,0,n+2,-1);
		for(int i=1;i<=n;++i)ans2=ans2*fc[d[i]-1]%MOD; 
		cout<<(ans1+MOD-ans2)%MOD<<'\n';
		return;
	}
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	tc[0]=1;
	fc[0]=1;
	for(int i=1;i<=100000;++i){
		tc[i]=tc[i-1]*(i==2?1:i)%MOD;
		fc[i]=fc[i-1]*i%MOD;
	}
	int c,t;cin>>c>>t;while(t--)solve(); 
}
/*

1 1
6 2
1 2
2 3
2 6
1 4
1 5
1 2

1 1
5 1
1 2
2 3
2 4
2 5
2
*/
