#include<cstdio>
#include<cstring>
const int N=1e5+5,M=2e5+5,mod=1e9+7;
#define ll long long
int tpe,T,n,k,S,h[N],v[M],nxt[M],tot,id[M],cnt; ll f[N],fac[N]; bool vis[N];
void add(int x,int y){v[++tot]=y; nxt[tot]=h[x]; h[x]=tot;}
struct edg{int u,v;}e[M];
void dfs1(int x,int fa){
	for(int i=h[x],y;i;i=nxt[i]){
		y=v[i]; if(y==fa) continue;
		for(int j=h[y],z;j;j=nxt[j]){
			z=v[j]; if(z==x) continue;
			e[++cnt]=(edg){id[(i-1)|1],id[(j-1)|1]};
			e[++cnt]=(edg){id[(j-1)|1],id[(i-1)|1]};
		}
		dfs1(y,x);
	}
}
void dfs2(int x,int fa){
	f[x]=1ll; int son=0;
	for(int i=h[x],y;i;i=nxt[i]){
		y=v[i]; if(y==fa) continue;
		++son; dfs2(y,x);
		f[x]=f[x]*f[y]%mod;
	}
	f[x]=f[x]*fac[son]%mod;
}
void sol(){
	memset(h,0,sizeof(h)); tot=cnt=0;
	scanf("%d%d",&n,&k);
	for(int i=1,x,y;i<n;++i){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x); id[(tot-1)|1]=i;
	}
	dfs1(1,0);
	memset(h,0,sizeof(h)); tot=0;
	for(int i=1;i<=cnt;++i) add(e[i].u,e[i].v);
	scanf("%d",&S); dfs2(S,0);
	printf("%lld\n",f[S]);
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=1; for(int i=1;i<=100000;++i) fac[i]=fac[i-1]*i%mod;
	scanf("%d%d",&tpe,&T); while(T--) sol();
	return 0;
} 
