#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
const int MOD = (int)(1e9) + 7;
vector<int> adj[MAXN];
int fac[MAXN], rev[MAXN], f[MAXN], subtree[MAXN];
int n;
int power(int x, int k, int MOD) {
if (k == 0) return 1 % MOD;
long long t = power(x, k / 2, MOD);
t = (t * t) % MOD;
if (k % 2 == 1) t = (t * x) % MOD;
return t;
}
void init() {
int n = 100000;
fac[0] = 1;
for(int i = 1; i <= n; i++) fac[i] = (1LL * i * fac[i - 1]) % MOD;
for(int i = 0; i <= n; i++) rev[i] = power(fac[i], MOD - 2, MOD);
}
int combi(int k, int n) {
return (1LL * fac[n] * ((1LL * rev[k] * rev[n - k]) % MOD)) % MOD;
}
void DFS(int u, int par = -1) {
f[u] = 1; subtree[u] = 1;
for(int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i];
if (v != par) {
DFS(v, u);
subtree[u] += subtree[v];
}
}
int s = subtree[u] - 1;
for(int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i];
if (v != par) {
int x = (1LL * combi(subtree[v], s) * f[v]) % MOD;
f[u] = (1LL * f[u] * x) % MOD;
s -= subtree[v];
}
}
}
int main()
{
init();
int test;
cin >> test;
while (test --) {
cin >> n;
for(int i = 1; i <= n; i++) adj[i].clear();
for(int i = 1; i <= n - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v); adj[v].push_back(u);
}
DFS(1);
cout << f[1] << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBNQVhOID0gMTAwMDAwICsgMTA7CmNvbnN0IGludCBNT0QgPSAoaW50KSgxZTkpICsgNzsKdmVjdG9yPGludD4gYWRqW01BWE5dOwppbnQgZmFjW01BWE5dLCByZXZbTUFYTl0sIGZbTUFYTl0sIHN1YnRyZWVbTUFYTl07CmludCBuOwppbnQgcG93ZXIoaW50IHgsIGludCBrLCBpbnQgTU9EKSB7CiAgIC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bdl0sIHMpICogZlt2XSkgJSBNT0Q7CiAgICAgICAgICAgIGZbdV0gPSAoMUxMICogZlt1XSAqIHgpICUgTU9EOwogICAgICAgICAgICBzIC09IHN1YnRyZWVbdl07CiAgICAgICAgfQogICAgfQp9CmludCBtYWluKCkKewogICAgaW5pdCgpOwogICAgaW50IHRlc3Q7CiAgICBjaW4gPj4gdGVzdDsKICAgIHdoaWxlICh0ZXN0IC0tKSB7CiAgICAgICAgY2luID4+IG47CiAgICAgICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspIGFkaltpXS5jbGVhcigpOwogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbiAtIDE7IGkrKykgewogICAgICAgICAgICBpbnQgdSwgdjsKICAgICAgICAgICAgY2luID4+IHUgPj4gdjsKICAgICAgICAgICAgYWRqW3VdLnB1c2hfYmFjayh2KTsgYWRqW3ZdLnB1c2hfYmFjayh1KTsKICAgICAgICB9CiAgICAgICAgREZTKDEpOwogICAgICAgIGNvdXQgPDwgZlsxXSA8PCBlbmRsOwogICAgfQp9