#include <algorithm>
#include <fstream>
#include <vector>
#include <bitset>
#include <string>
#include <array>

#define rgall(arr) (arr).begin(),(arr).end()
#define rgcnt(arr,cnt) (arr).begin(),(arr).begin()+(cnt)
#define rgo1(arr,cnt) (arr).begin()+1,(arr).begin()+(cnt)+1

using namespace std;

//#define int long long

ifstream cin("traverse.in");
ofstream cout("traverse.out");

long long fast_pow(long long a,long long b,long long m)
{
	long long c=1;
	while(b)
	{
		if(b&1)
			c=c*a%m;
		a=a*a%m;
		b>>=1;
	}
	return c;
}
long long inverse(long long a,long long p)
{
	return fast_pow(a,p-2,p);
}

array<array<long long,2>,100001>	dp;
array<pair<int,int>,100001> 		edges;
array<vector<int>,100001> 			tree;
array<long long,100001> 			facts,ifacts,invs,idegs;
array<int,100001> 					deps;
const long long 					moder=1e9+7;
bitset<100001>						isrt;
vector<int> 						eids;
long long 							answer;

void DFS_init(int u,int father)
{
	deps[u]=deps[father]+1;
	for(int i:tree[u])
		if(i!=father)
			DFS_init(i,u);
}
void DFS_dp(int u,int father)
{
	if(u!=1&&tree[u].size()==1)
	{
		dp[u][isrt[u]]=1;
		return;
	}
	long long test=0;
	for(int i:tree[u])
		if(i!=father)
		{
			DFS_dp(i,u);
			for(int j=0;j<2;j++)
				dp[u][j]+=dp[i][j]*idegs[i]%moder;
			for(int i=0;i<2;i++)
				dp[u][i]%=moder;
		}
	test%=moder;
	long long a=(dp[u][1]+dp[u][0])%moder*(dp[u][1]+dp[u][0])%moder-dp[u][0]*dp[u][0]%moder+moder;
	a%=moder;
	for(int i:tree[u])
		if(i!=father)
		{
			long long b=dp[i][1]*idegs[i]%moder;
			a+=moder-b*b%moder,a%=moder;
		}
	a%=moder;
	answer+=a%moder*(moder+1>>1)%moder*idegs[u]%moder;
//	cout<<a%moder*idegs[u]%moder<<' '<<u<<endl;
	if(u==1&&tree[u].size()==1)
		answer+=dp[u][1]*idegs[u]%moder;
	if(isrt[u])
		(dp[u][1]+=dp[u][0])%=moder,dp[u][0]=0;
	// if(test*idegs[u]%moder!=1)
	// 	cout<<u<<"|\n";
	// if((dp[u][1]+dp[u][0])%moder*idegs[u]%moder!=1)
	// 	cout<<u<<"|\n";
	// cout<<(dp[u][1]+dp[u][0])%moder*idegs[u]%moder;
}

signed main(int argc,char* argv[])
{
	ios::sync_with_stdio(false);
	for(int i=facts[0]=1;i<=1e5;i++)
		facts[i]=facts[i-1]*i%moder;
	ifacts[1e5]=inverse(facts[1e5],moder);
	for(int i=1e5;i;i--)
		ifacts[i-1]=ifacts[i]*i%moder,invs[i]=ifacts[i]*facts[i-1]%moder;
	int testcnt;
	cin>>testcnt>>testcnt;
	while(testcnt--)
	{
		//Remember to clear!
		int cnt,cnte;
		cin>>cnt>>cnte;
		for(int i=1;i<cnt;i++)
		{
			int u,v;
			cin>>u>>v;
			tree[u].push_back(v),tree[v].push_back(u);
			edges[i]=make_pair(u,v);
		}
		eids.resize(cnte);
		for(int& i:eids)
			cin>>i;
		if(cnt==2)
			cout<<"1\n";
		else
		{
			answer=0;
			DFS_init(1,0);
			for(int i:eids)
			{
				auto a=edges[i];
				if(deps[a.first]>deps[a.second])
					swap(a.first,a.second);
				isrt.set(a.second);
				// cout<<a.second<<' ';
			}
			// cout<<endl;
			for(int i=1;i<=cnt;i++)
				if(tree[i].size()==1)
					idegs[i]=1;
				else
					idegs[i]=invs[tree[i].size()-1];
			if(cnte>1)
				DFS_dp(1,0);
			else
				answer=1;
			answer%=moder;
			// cout<<endl;
			// cout<<answer<<endl;
			// answer=1;
//			cout<<tree[1].size()<<'\n';
			for(int i=1;i<=cnt;i++)
				answer=answer*facts[tree[i].size()-1]%moder;
			cout<<answer<<'\n';
		}
		for(int i=1;i<=cnt;i++)
			tree[i].clear(),isrt.reset(i);
		for(int i=1;i<=cnt;i++)
			dp[i].fill(0);
		eids.clear();
//		cout<<endl;
	}
	return 0;
}
//Any node in the tree becomes a chain in the hyper spanning tree.
//Since they are independent and contains no cycle,there are some nice properties.
//Chain count:f(n)=([n<2]+n!)/2.Well of course n>1 :P
//Consider rooting the tree.Every chain corresponding the clique brings a constraint on the root:either on subtree(s or t).
//It's hard to record if the critical root exists directly.Let's assume a root for a tree.
//Make 1 the root of original tree.then only critical edge which has less DFS order can be the root.
//Gotta Go Fast.Last 30 min is important.
//Easy to handle valid roots.
//Oh no.A leaf is always valid.And the valid roots form a chain,begin and ends at leaves!
//Not on the chain:always points to the chain.prod (deg-1)!.
//On the chain:points toward the endpoints.prod (deg-2)!.
//10:54  I'm a little hungry now :\
//prod (deg-2)! * sum prod_{i on chain} 1/(deg-1)
//11:12 Let's Go!
