#include<bits/stdc++.h>
#define mems(x,y) memset(x,y,sizeof x)
#define eb emplace_back
#define Mp make_pair
#define il inline
#define gc getchar
#define pc putchar
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define drep(i,x,y) for(int i=(x);i>=(y);i--)
#define go(i,u) for(int i=head[u];i;i=e[i].nxt)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>
il void read(T &x){
	int f=1;x=0;
	char c=gc();
	while(c<'0'||c>'9'){
		if(c=='-'){
			f=-1;
		}
		c=gc();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=gc();
	}
	x*=f;
}
template<typename T,typename ...Args>
void read(T &x,Args &...args){
	read(x),read(args...);
}
const int N=1e5+7,M=-1,inf=0x3f3f3f3f,mod=1e9+7;
const ll INF=1ll*inf*inf;
int n,m,c[N],deg[N],fac[N],dp[N][4];
bool pd[N];
int tot,head[N];
struct node{
	int to,nxt;
}e[N<<1];
il void add(int u,int v){
	e[++tot]={v,head[u]},head[u]=tot;
}
il int Mod(int x,int y){
	return x+y>=mod?x+y-mod:x+y;
}
il int qpow(int x,int y){
	int ret=1;
	while(y){
		if(y&1){
			ret=1ll*ret*x%mod;
		}
		x=1ll*x*x%mod,y>>=1;
	}
	return ret;
}
void Yorushika(){
	read(n,m);
	bool fl1=1,fl2=1;
	rep(i,1,n-1){
		int u,v;read(u,v);
		fl1&=u==i&&v==i+1;
		fl2&=u==1&&v==i+1;
	}
	rep(i,1,m){
		int x;read(x);
	}
	if(fl1){
		puts("1");
	}else{
		int t=Mod(1ll*m*(n-1-m)%mod,1ll*m*(m-1)/2%mod);
		rep(i,1,n-3){
			t=1ll*t*i%mod;
		}
		printf("%d\n",t);
	}
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int t=1,yinhee;
	read(yinhee,t);
	while(t--){
		Yorushika();
	}
}
/*
寄,tyl
#include<bits/stdc++.h>
#define mems(x,y) memset(x,y,sizeof x)
#define eb emplace_back
#define Mp make_pair
#define il inline
#define gc getchar
#define pc putchar
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define drep(i,x,y) for(int i=(x);i>=(y);i--)
#define go(i,u) for(int i=head[u];i;i=e[i].nxt)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>
il void read(T &x){
	int f=1;x=0;
	char c=gc();
	while(c<'0'||c>'9'){
		if(c=='-'){
			f=-1;
		}
		c=gc();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=gc();
	}
	x*=f;
}
template<typename T,typename ...Args>
void read(T &x,Args &...args){
	read(x),read(args...);
}
const int N=1e5+7,M=-1,inf=0x3f3f3f3f,mod=1e9+7;
const ll INF=1ll*inf*inf;
int n,m,c[N],deg[N],fac[N],dp[N][4];
bool pd[N];
int tot,head[N];
struct node{
	int to,nxt;
}e[N<<1];
il void add(int u,int v){
	e[++tot]={v,head[u]},head[u]=tot;
}
il int Mod(int x,int y){
	return x+y>=mod?x+y-mod:x+y;
}
il int qpow(int x,int y){
	int ret=1;
	while(y){
		if(y&1){
			ret=1ll*ret*x%mod;
		}
		x=1ll*x*x%mod,y>>=1;
	}
	return ret;
}
void dfs1(int u,int f){
	c[u]=0;
	go(i,u){
		int v=e[i].to;
		if(v==f){
			continue;
		}
		dfs1(v,u);
		c[u]+=c[v]+pd[(i+1)/2];
	}
}
int calc(vector<int> &g,int l,int r){
	int ret=1;
	rep(i,l,r){
		ret=1ll*ret*g[i]%mod;
	}
	return ret;
}
void dfs2(int u,int f){
	dp[u][0]=dp[u][2]=0,dp[u][1]=1;
	int cnt=0;
	vector<int> g;
	g.eb(0);
	go(i,u){
		int v=e[i].to;
		if(v==f){
			continue;
		}
		dfs2(v,u);
		dp[u][1]=1ll*dp[u][1]*dp[v][1]%mod;
		g.eb(dp[v][1]);
		cnt+=pd[(i+1)/2];
	}
	int A=0;
	go(i,u){
		int v=e[i].to;
		if(v==f){
			continue;
		}
		A++;
		int t=1ll*calc(g,1,A-1)*calc(g,A+1,g.size()-1)%mod;
		if(m-c[u]>0){
			dp[u][0]=Mod(dp[u][0],1ll*t*Mod(dp[v][0],dp[v][1]*pd[(i+1)/2])%mod*fac[deg[u]-2]%mod);
		}else{
			dp[u][2]=Mod(dp[u][2],1ll*t*Mod(dp[v][0],dp[v][1]*pd[(i+1)/2])%mod*fac[deg[u]-2]%mod);
		}
		dp[u][2]=Mod(dp[u][2],1ll*t*dp[v][2]%mod*fac[deg[u]-2]%mod);
	}
	A=0;
	go(i,u){
		int v=e[i].to;
		if(v==f){
			continue;
		}
		A++;
		int B=0;
		go(j,u){
			int w=e[j].to;
			if(w==f){
				continue;
			}
			B++;
			if(A>=B){
				continue;
			}
			int t=1ll*calc(g,1,A-1)*calc(g,A+1,B-1)%mod*calc(g,B+1,g.size()-1)%mod;
			int x=c[v]+pd[(i+1)/2],y=c[w]+pd[(j+1)/2];
			if(x&&y){
				dp[u][2]=Mod(dp[u][2],1ll*t*(c[v]>0?dp[v][0]:dp[v][1])%mod*(c[w]>0?dp[w][0]:dp[w][1])%mod*fac[deg[u]-2]%mod);
			}else if(x){
				// printf("%d %d %d\n",c[v],pd[(i+1)/2],(!c[v])+2*(!pd[(i+1)/2]));
				dp[u][2]=Mod(dp[u][2],1ll*t*dp[v][(!c[v])+2*(!pd[(i+1)/2])]%mod*dp[w][1]%mod*fac[deg[u]-2]%mod);
			}else if(y){
				dp[u][2]=Mod(dp[u][2],1ll*t*dp[w][(!c[w])+2*(!pd[(j+1)/2])]%mod*dp[v][1]%mod*fac[deg[u]-2]%mod);
			}
		}
	}
	if(deg[u]>1){
		dp[u][1]=1ll*dp[u][1]*fac[deg[u]-2]%mod*(deg[u]-cnt-1)%mod*(m-c[u]>0);
	}
	// printf("%d %d %d %d\n",u,dp[u][0],dp[u][1],dp[u][2]);
	// if(fl){
// 		
	// }
}
void Yorushika(){
	read(n,m);
	mems(head,0),mems(deg,0),tot=0;
	rep(i,1,n-1){
		int u,v;read(u,v);
		add(u,v),add(v,u);
		deg[u]++,deg[v]++;
	}
	fac[0]=1;
	rep(i,1,n){
		fac[i]=1ll*fac[i-1]*i%mod;
	}
	mems(pd,0);
	rep(i,1,m){
		int x;read(x);
		pd[x]=1;
	}
	int u=e[1].to,v=e[2].to;
	dfs1(u,v),dfs1(v,u);
	dfs2(u,v),dfs2(v,u);
	int ans=Mod(1ll*dp[u][0]*Mod(dp[v][1],dp[v][2])%mod,1ll*Mod(dp[u][1],dp[u][2])*dp[v][0]%mod);
	ans=Mod(ans,Mod(1ll*dp[u][1]*dp[v][2]%mod,1ll*dp[u][2]*dp[v][1]%mod));
	if(pd[1]){
		ans=Mod(ans,1ll*dp[u][1]*dp[v][1]%mod);
	}
	printf("%d\n",ans);
}
signed main(){
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	int t=1,yinhee;
	read(yinhee,t);
	while(t--){
		Yorushika();
	}
}
*/