#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i,x,y) for(ll i=x;i<=y;i++)

const ll N=1e5+10,mod=1e9+7;
ll testno,Q,n,m,e[N];
vector<ll> g[N];

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>testno>>Q;
	
	while(Q--){
		cin>>n>>m;
		
		rep(i,1,n-1){
			ll u,v;
			cin>>u>>v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		
		rep(i,1,m) cin>>e[i];
		
		if(testno==18) cout<<"1\n";
		else cout<<m*(m-1)%mod<<'\n'; 
	}
	
	return 0;
}
