#include<bits/stdc++.h>
using namespace std;
const long long MOD=1e9+7;
int c,t;
int n,k;
vector<int> v[100000+5];
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d%d",&x,&y);
		}
		long long ans=1ll;
		for(int i=1;i<=n;i++){
			ans*=i;
			ans%=MOD;
		}
		printf("%lld",ans);
	}
}
