# Solution

f[i][j]表示第i个节点前有j个节点的方案数

# Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define sqz main
#define ll long long
#define reg register int
#define rep(i, a, b) for (reg i = a; i <= b; i++)
#define per(i, a, b) for (reg i = a; i >= b; i--)
#define travel(i, u) for (reg i = head[u]; i; i = edge[i].next)
const int INF = 1e9, N = 1000, mo = INF + 7;0
const double eps = 1e-6, phi = acos(-1);
ll mod(ll a, ll b) {if (a >= b || a < 0) a %= b; if (a < 0) a += b; return a;}
ll read(){ ll x = 0; int zf = 1; char ch; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;}
void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + '0');}
int f[N + 5][N + 5], g[N + 5][N + 5], now[N + 5], Size[N + 5], num = 0, head[N + 5], C[N + 5][N + 5];
struct node
{
int vet, val, next;
}edge[2 * N + 5];
{
edge[++num].vet = v;
edge[num].val = 0;
edge[++num].vet = u;
edge[num].val = 1;
}
void dfs(int u, int fa)
{
Size[u] = f[u][0] = 1;
travel(i, u)
{
int v = edge[i].vet;
if (v == fa) continue;
dfs(v, u);
memset(now, 0, sizeof now);
if (edge[i].val)
{
rep(j, 0, Size[u])
rep(k, 0, Size[v])
now[j + k] = (now[j + k] + (ll)C[j + k][j] * C[Size[u] + Size[v] - j - k - 1][Size[v] - k]
% mo * f[u][j] % mo * g[v][k - 1] % mo) % mo;
}
else
{
rep(j, 0, Size[u])
rep(k, 0, Size[v])
now[Size[u] + Size[v] - j - k - 1] = (now[Size[u] + Size[v] - j - k - 1] + (ll)C[j + k][j] * C[Size[u] + Size[v] - j - k - 1][Size[v] - k]
% mo * f[u][Size[u] - j - 1] % mo * (g[v][Size[v] - 1] - g[v][Size[v] - k - 1] + mo) % mo) % mo;
}
Size[u] += Size[v];
rep(j, 0, Size[u]) f[u][j] = now[j];
}
g[u][0] = f[u][0];
rep(i, 1, Size[u]) g[u][i] = (g[u][i - 1] + f[u][i]) % mo;
}
int sqz()
{
rep(i, 0, N)
{
C[i][0] = 1;
rep(j, 1, i)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mo;
}
while (H_H--)
{
num = 0;