#include <bits/stdc++.h>
using namespace std ;
#define LL long long
#define MOD 1000000007
#define MAXN 100005
LL SubTree[MAXN],TopoCount[MAXN],Fact[MAXN],Inv[MAXN];
vector<int> adj[MAXN] ;
int N,T,U,V;
LL inv(LL a,LL b){
LL res = 1 ;
a %= MOD ;
while(b){
if(b%2){
res = (res*a)%MOD ;
}
a = (a*a)%MOD ;
b /= 2 ;
}
return res%MOD ;
}
void pre(){
Fact[0] = 1 ;
Inv[0] = 1 ;
for(int i=1;i<MAXN;i++){
Fact[i] = (1LL * Fact[i-1] * i)%MOD ;
assert(Fact[i] >= 0) ;
}
for(int i=1;i<MAXN;i++){
Inv[i] = inv(Fact[i],MOD-2) ;
assert(Inv[i] >= 0) ;
}
}
LL nCr(int N,int R){
return (1LL * Fact[N] * (1LL * Inv[N-R] * Inv[R])%MOD )%MOD ;
}
void dfs(int u,int p=-1){
SubTree[u] = 1 ;
TopoCount[u] = 1 ;
for(vector<int> :: iterator it = adj[u].begin();it!=adj[u].end();++it){
if(*it != p){
dfs(*it,u) ;
SubTree[u] += SubTree[*it] ;
}
}
int subtree = (SubTree[u]-1) ;
for(vector<int> :: iterator it = adj[u].begin();it!=adj[u].end();++it){
if(*it != p){
dfs(*it,u) ;
LL x = (1LL * nCr(subtree,SubTree[*it]) * TopoCount[*it])%MOD ;
TopoCount[u] = (1LL * TopoCount[u] * x)%MOD ;
subtree -= SubTree[*it] ;
}
}
}
int main(){
pre() ;
scanf("%d",&T) ;
while(T--){
scanf("%d",&N) ;
for(int i=1;i<N;i++){
scanf("%d%d",&U,&V) ;
adj[U].push_back(V) ;
adj[V].push_back(U) ;
}
dfs(1) ;
printf("%lld\n",TopoCount[1]%MOD) ;
for(int i=1;i<=N;i++)
adj[i].clear() ;
memset(SubTree,0,sizeof SubTree) ;
memset(TopoCount,0,sizeof TopoCount) ;
}
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQgOwoKI2Rl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