AtCoder Beginner Contest 160 - Distributing Integers

We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i.
For each k=1, ..., N, solve the problem below:
 - Consider writing a number on each vertex in the tree in the following manner:
 - First, write 1 on Vertex k.
 - Then, for each of the numbers 2, ..., N in this order, write the number on the vertex chosen as follows:
 - Choose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.
 - Find the number of ways in which we can write the numbers on the vertices, modulo (10^9+7).

-----Constraints-----
 - 2 \leq N \leq 2 \times 10^5
 - 1 \leq a_i,b_i \leq N
 - The given graph is a tree.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 b_1
:
a_{N-1} b_{N-1}

-----Output-----
For each k=1, 2, ..., N in this order, print a line containing the answer to the problem.

-----Sample Input-----
3
1 2
1 3

-----Sample Output-----
2
1
1

The graph in this input is as follows:

For k=1, there are two ways in which we can write the numbers on the vertices, as follows:
 - Writing 1, 2, 3 on Vertex 1, 2, 3, respectively
 - Writing 1, 3, 2 on Vertex 1, 2, 3, respectively

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
import sys
from functools import reduce

def rerooting(N, adj, merge, finalize, identity):
	order = [None] * N
	parent = [None] * N
	parent[0] = -1
	stack = [0]
	for i in range(N):
		v = stack.pop()
		order[i] = v
		for u in adj[v]:
			if parent[u] is None:
				parent[u] = v
				stack.append(u)
	dp_down = [None] * N
	for v in reversed(order[1:]):
		p = parent[v]
		dp_down[v] = finalize(reduce(merge, (dp_down[c] for c in adj[v] if c != p), identity))
	dp_up = [None] * N
	dp_up[0] = identity
	for v in order:
		if len(adj[v]) == 1 and adj[v][0] == parent[v]:
			continue
		p = parent[v]
		left = [dp_up[v]]
		for u in adj[v]:
			if u != p:
				left.append(merge(left[-1], dp_down[u]))
		right = [identity]
		for u in reversed(adj[v]):
			if u != p:
				right.append(merge(dp_down[u], right[-1]))
		i = 0
		for u in adj[v]:
			if u != p:
				dp_up[u] = finalize(merge(left[i], right[-i - 2]))
				i += 1
	for (v, l) in enumerate(adj):
		order[v] = reduce(merge, (dp_down[u] for u in adj[v] if u != parent[v]), identity)
		order[v] = finalize(merge(order[v], dp_up[v]))
	return order

def solve(N, edges):
	MOD = 10 ** 9 + 7
	factorio = [1] * (N + 1)
	t = 1
	for i in range(1, N + 1):
		t *= i
		t %= MOD
		factorio[i] = t
	adj = [[] for _ in range(N)]
	for (a, b) in edges:
		adj[a].append(b)
		adj[b].append(a)

	def func(x, y):
		(cx, nx) = x
		(cy, ny) = y
		c = cx * cy * factorio[nx + ny] * pow(factorio[nx] * factorio[ny], MOD - 2, MOD)
		c %= MOD
		n = nx + ny
		return (c, n)

	def func2(x):
		(c, n) = x
		return (c, n + 1)
	identity = (1, 0)
	res = rerooting(N, adj, func, func2, identity)
	for (k, n) in res:
		print(k)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = map(int, read().split())
edges = tuple(((a - 1, b - 1) for (a, b) in zip(m, m)))
solve(N, edges)


import sys
sys.setrecursionlimit(10 ** 7)
M = 10 ** 9 + 7
N = 10 ** 6
fac = [0] * (N + 1)
fac[0] = b = 1
for i in range(1, N + 1):
	fac[i] = b = b * i % M
inv = [0] * (N + 1)
inv[N] = b = pow(fac[N], M - 2, M)
for i in range(N, 0, -1):
	inv[i - 1] = b = b * i % M

def dfs1(v, p):
	s = 1
	l = []
	(c1, c2) = ([1], [1])
	for w in e[v]:
		if w == p:
			continue
		l += (w,)
		dfs1(w, v)
		u = sz1[w]
		c1 += (c1[-1] * dp1[w] * inv[u] % M,)
		s += u
	for w in l[::-1]:
		c2 += (c2[-1] * dp1[w] * inv[sz1[w]] % M,)
	e[v] = l
	c[v] = (c1, c2[::-1])
	sz1[v] = s
	dp1[v] = c1[-1] * fac[s - 1] % M
(n, *t) = open(0).read().split()
n = int(n)
e = [[] for _ in range(n)]
for (a, b) in zip(*[map(int, t)] * 2):
	e[a - 1] += (b - 1,)
	e[b - 1] += (a - 1,)
(sz1, sz2) = ([0] * n, [0] * n)
(dp1, dp2) = ([0] * n, [0] * n)
c = [[] for _ in range(n)]
dfs1(0, -1)
sz2[0] = 1
dp2[0] = 1
s = [0]
while s:
	v = s.pop()
	l = len(e[v])
	(c1, c2) = c[v]
	uv = sz2[v] - 1
	tv = dp2[v] * inv[uv]
	for (i, w) in enumerate(e[v]):
		tw = c1[i] * c2[i + 1] % M
		uw = uv + sz1[v] - sz1[w] - 1
		dp2[w] = tv * tw * fac[uw] % M
		sz2[w] = uw + 2
		s += (w,)
for i in range(n):
	u1 = sz1[i] - 1
	u2 = sz2[i] - 1
	print(dp1[i] * dp2[i] * inv[u1] * inv[u2] * fac[u1 + u2] % M)


import sys
input = sys.stdin.readline
from collections import deque
nn = 200200
mod = 10 ** 9 + 7
fa = [1] * (nn + 1)
fainv = [1] * (nn + 1)
inv = [1] * (nn + 1)
for i in range(nn):
	fa[i + 1] = fa[i] * (i + 1) % mod
fainv[-1] = pow(fa[-1], mod - 2, mod)
for i in range(nn)[::-1]:
	fainv[i] = fainv[i + 1] * (i + 1) % mod
for i in range(1, nn)[::-1]:
	inv[i] = fainv[i] * fa[i - 1]
C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a - b] % mod if 0 <= b <= a else 0
N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
	(x, y) = map(int, input().split())
	X[x - 1].append(y - 1)
	X[y - 1].append(x - 1)
P = [-1] * N
Q = deque([0])
R = []
while Q:
	i = deque.popleft(Q)
	R.append(i)
	for a in X[i]:
		if a != P[i]:
			P[a] = i
			X[a].remove(i)
			deque.append(Q, a)
BU = [1] * N
TD = [1] * N
SI = [1] * N
for i in R[::-1]:
	a = 1
	s = 1
	for j in X[i]:
		a = a * BU[j] % mod
		s += SI[j]
	SI[i] = s
	BU[i] = inv[s] * a % mod
for i in R:
	c = len(X[i])
	AL = [1] * (c + 1)
	AR = [1] * (c + 1)
	for (k, j) in enumerate(X[i]):
		AL[k + 1] = AL[k] * BU[j] % mod
	for k in range(c - 1, 0, -1):
		j = X[i][k]
		AR[k] = AR[k + 1] * BU[j] % mod
	for (k, j) in enumerate(X[i]):
		TD[j] = TD[i] * AL[k] % mod * AR[k + 1] % mod * inv[N - SI[j]] % mod
print(*[BU[i] * fa[SI[i]] % mod * TD[i] % mod * fa[N - SI[i]] % mod * C(N - 1, SI[i] - 1) % mod for i in range(N)], sep='\n')


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = map(int, read().split())
AB = zip(m, m)
MOD = 10 ** 9 + 7
graph = [[] for _ in range(N + 1)]
for (a, b) in AB:
	graph[a].append(b)
	graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)
fact = [1] * (N + 10)
for n in range(1, N + 10):
	fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
	fact_inv[n - 1] = fact_inv[n] * n % MOD
size_d = [0] * (N + 1)
dp_d = [1] * (N + 1)
for v in order[::-1]:
	dp_d[v] *= fact[size_d[v]]
	dp_d[v] %= MOD
	p = parent[v]
	s = size_d[v] + 1
	size_d[p] += s
	dp_d[p] *= fact_inv[s] * dp_d[v]
	dp_d[p] %= MOD
size_u = [N - 2 - x for x in size_d]
dp_u = [1] * (N + 1)
for v in order[1:]:
	p = parent[v]
	x = dp_d[p]
	x *= dp_u[p]
	x *= fact_inv[size_d[p]]
	x *= fact[size_d[v] + 1]
	x *= pow(dp_d[v], MOD - 2, MOD)
	x *= fact[size_u[v]]
	x *= fact_inv[size_u[p] + 1]
	dp_u[v] = x % MOD
for (xd, xu, sd, su) in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
	su += 1
	x = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % MOD
	print(x)


import sys
sys.setrecursionlimit(10 ** 5 * 2 + 10)
MOD = 10 ** 9 + 7
inv = [None, 1]
for i in range(2, 10 ** 5 * 2 + 1):
	inv.append(MOD - MOD // i * inv[MOD % i] % MOD)
fact = [1]
ifact = [1]
for i in range(1, 10 ** 5 * 2 + 1):
	fact.append(i * fact[-1] % MOD)
	ifact.append(inv[i] * ifact[-1] % MOD)

class Node:

	def __init__(self, ind):
		self.ind = ind
		self.val = 1
		self.ndesc = 1
		self.neighs = []

	def calc(self, fro):
		for neigh in self.neighs:
			if neigh.ind == fro:
				continue
			neigh.calc(self.ind)
			self.val = self.val * neigh.val * ifact[neigh.ndesc] % MOD
			self.ndesc += neigh.ndesc
		self.val = self.val * fact[self.ndesc - 1] % MOD

	def comp(self, fro, carry):
		self.val = carry * self.ndesc * inv[max(1, N - self.ndesc)] % MOD
		for neigh in self.neighs:
			if neigh.ind == fro:
				continue
			neigh.comp(self.ind, self.val)
N = int(input())
nodes = [Node(i) for i in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	nodes[a - 1].neighs.append(nodes[b - 1])
	nodes[b - 1].neighs.append(nodes[a - 1])
nodes[0].calc(0)
nodes[0].comp(0, nodes[0].val * inv[N] % MOD)
for i in range(N):
	print(nodes[i].val)


def COMinit(n, MOD):
	fact = [1, 1]
	fact_inv = [1, 1]
	inv = [0, 1]
	for i in range(2, n + 1):
		fact.append(fact[-1] * i % MOD)
		inv.append(-inv[MOD % i] * (MOD // i) % MOD)
		fact_inv.append(fact_inv[-1] * inv[i] % MOD)
	return (fact, fact_inv)
MOD = 10 ** 9 + 7

def resolve():

	def dfs1(r_topo, par):
		for idx in reversed(r_topo):
			for to in G[idx]:
				if to == par[idx]:
					continue
	N = int(input())
	G = [[] for _ in range(N)]
	for _ in range(N - 1):
		(a, b) = map(lambda x: int(x) - 1, input().split())
		G[a].append(b)
		G[b].append(a)
	(fact, fact_inv) = COMinit(N, MOD)
	topo = []
	P = [-1] * N
	node = [0]
	while node:
		v = node.pop()
		topo.append(v)
		for to in G[v]:
			if to == P[v]:
				continue
			P[to] = v
			node.append(to)
	size = [1] * N
	for e in reversed(topo):
		if e == 0:
			break
		size[P[e]] += size[e]
	dp1 = [1] * N
	for e in reversed(topo):
		dp1[e] = dp1[e] * fact[size[e] - 1] % MOD
		if e == 0:
			break
		dp1[P[e]] = dp1[P[e]] * dp1[e] % MOD * fact_inv[size[e]] % MOD
	dp2 = [0] * N
	dp2[0] = dp1[0]
	for e in topo[1:]:
		p = P[e]
		tmp = dp2[p] * fact[N - 1 - size[e]] % MOD * fact[size[e]] % MOD
		red = tmp * fact_inv[N - 1] % MOD * pow(dp1[e], MOD - 2, MOD) % MOD
		size_red = N - size[e]
		tmp = dp1[e] * red % MOD * fact[N - 1] % MOD
		dp2[e] = tmp * fact_inv[size[e] - 1] % MOD * fact_inv[size_red] % MOD
	print(*dp2, sep='\n')

def __starting_point():
	resolve()
__starting_point()


class ReRooting(object):

	def merge(self, a, b):
		return a * b % MOD

	def adj_bu(self, accBU, v: int):
		return accBU * inv(self.SIZE[v]) % MOD

	def adj_td(self, accTD, v: int, p: int):
		return accTD * inv(self.V - self.SIZE[v]) % MOD

	def adj_fin(self, acc, v: int):
		return acc * fact[self.V - 1] % MOD

	def __init__(self, V: int, e: int):
		(self.V, self.e) = (V, e)
		self.edge = [[] for _ in range(V)]
		self.par = [-1] * V
		self.order = []
		self.SIZE = [1] * self.V

	def subtree_size(self):
		for v in reversed(self.order[1:]):
			self.SIZE[self.par[v]] += self.SIZE[v]

	def add_edge(self, u: int, v: int):
		self.edge[u].append(v)
		self.edge[v].append(u)

	def topological_sort(self, root: int=0):
		from collections import deque
		que = deque([root])
		while que:
			v = que.popleft()
			self.order.append(v)
			for w in self.edge[v]:
				if w != self.par[v]:
					self.par[w] = v
					que.append(w)

	def bottom_up(self):
		root = self.order[0]
		accBU = [self.e] * self.V
		resBU = [self.e] * self.V
		for v in reversed(self.order):
			resBU[v] = self.adj_bu(accBU[v], v)
			if v == root:
				break
			p = self.par[v]
			accBU[p] = self.merge(accBU[p], resBU[v])
		return (accBU, resBU)

	def top_down(self, resBU: list):
		accTD = [self.e] * self.V
		resTD = [self.e] * self.V
		for p in self.order:
			ac = resTD[p]
			for v in self.edge[p]:
				if v == self.par[p]:
					continue
				accTD[v] = ac
				ac = self.merge(ac, resBU[v])
			ac = self.e
			for v in reversed(self.edge[p]):
				if v == self.par[p]:
					continue
				accTD[v] = self.merge(accTD[v], ac)
				ac = self.merge(ac, resBU[v])
				resTD[v] = self.adj_td(accTD[v], v, p)
		return resTD

	def solve(self):
		self.topological_sort()
		self.subtree_size()
		(accBU, resBU) = self.bottom_up()
		resTD = self.top_down(resBU)
		res = [self.adj_fin(self.merge(a, b), v) for (v, (a, b)) in enumerate(zip(accBU, resTD))]
		return res
N = int(input())
MOD = 10 ** 9 + 7
fact = [1] * (N + 1)
factinv = [1] * (N + 1)
for i in range(N):
	fact[i + 1] = fact[i] * (i + 1) % MOD
factinv[-1] = pow(fact[-1], MOD - 2, MOD)
for i in range(N - 1, -1, -1):
	factinv[i] = factinv[i + 1] * (i + 1) % MOD
inv = lambda n: fact[n - 1] * factinv[n] % MOD

def main():
	RR = ReRooting(N, 1)
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		RR.add_edge(a - 1, b - 1)
	print(*RR.solve(), sep='\n')

def __starting_point():
	main()
__starting_point()


from functools import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
M = 10 ** 9 + 7
N = int(input())

@lru_cache(maxsize=None)
def mod_inv(x):
	if x == 1:
		return 1
	return M // x * -mod_inv(M % x) % M
weight = [0] * (N + 1)
size = [0] * (N + 1)

def calc_subtree(v):
	W = 1
	S = 1
	for child in Edge[v]:
		Edge[child].remove(v)
		(w, s) = calc_subtree(child)
		W = W * w % M
		S += s
	weight[v] = W * S % M
	size[v] = S
	return (weight[v], size[v])
ans = [0] * (N + 1)

def set_ans(v, a):
	ans[v] = a
	for child in Edge[v]:
		n = size[child]
		set_ans(child, ans[v] * n * mod_inv(N - n) % M)
Edge = defaultdict(set)
fact = N
for i in range(1, N):
	fact = fact * i % M
	(a, b) = map(int, input().split())
	Edge[a].add(b)
	Edge[b].add(a)
calc_subtree(1)
set_ans(1, mod_inv(weight[1]) * fact % M)
for i in range(1, N + 1):
	print(ans[i])


import sys
from collections import deque
sys.setrecursionlimit(1000000)

def comb(n, r, fact, revfact, mod):
	return fact[n] * (revfact[n - r] * revfact[r]) % mod % mod

def dfs(i, parent, DP, sNum, E, fact, revfact, mod):
	Ans = 1
	sonNode = 1
	S = []
	for e in E[i]:
		if e != parent:
			(mult, sn) = dfs(e, i, DP, sNum, E, fact, revfact, mod)
			S.append(sn)
			Ans *= mult
			Ans %= mod
			sonNode += sn
	stotal = sonNode - 1
	for s in S:
		Ans *= comb(stotal, s, fact, revfact, mod)
		Ans %= mod
		stotal -= s
	DP[i] = Ans
	sNum[i] = sonNode - 1
	return (Ans, sonNode)

def solve():
	input = sys.stdin.readline
	N = int(input())
	E = [[] for _ in range(N)]
	for _ in range(N - 1):
		(a, b) = list(map(int, input().split()))
		E[a - 1].append(b - 1)
		E[b - 1].append(a - 1)
	mod = 7 + 10 ** 9
	fact = [1] * (N + 1)
	for i in range(N):
		fact[i + 1] = (i + 1) * fact[i] % mod
	revfact = [1] * (N + 1)
	revfact[N] = pow(fact[N], mod - 2, mod)
	for i in reversed(list(range(N))):
		revfact[i] = (i + 1) * revfact[i + 1] % mod
	DP = [1] * N
	sNum = [0] * N
	usNum = [0] * N
	dfs(0, 0, DP, sNum, E, fact, revfact, mod)
	q = deque()
	for e in E[0]:
		q.append((e, 0))
	while q:
		(nn, parn) = q.popleft()
		upperMult = DP[parn] * pow(comb(N - 1, sNum[nn] + 1, fact, revfact, mod), mod - 2, mod)
		usNum[nn] = upperNum = sNum[parn] - sNum[nn] + usNum[parn]
		DP[nn] = upperMult * comb(N - 1, upperNum, fact, revfact, mod) % mod
		for e in E[nn]:
			if e != parn:
				q.append((e, nn))
	print('\n'.join(map(str, DP)))
	return 0

def __starting_point():
	solve()
__starting_point()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10 ** 5 + 100)
MAX = 2 * 10 ** 5 + 100
MOD = 10 ** 9 + 7
fact = [0] * MAX
inv = [0] * MAX
finv = [0] * MAX
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
	fact[i] = fact[i - 1] * i % MOD
	inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD

def C(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD

def dfs1(v, pv):
	res = 1
	M = 0
	for nv in G[v]:
		if nv == pv:
			continue
		(num, res2) = dfs1(nv, v)
		res *= finv[num] * res2
		res %= MOD
		M += num
	res *= fact[M]
	res %= MOD
	st[v] = res
	chi[v] = M + 1
	return (M + 1, res)

def dfs2(v, pv):
	res = rt[pv] * fact[chi[v]] * fact[N - chi[v] - 1] * pow(st[v], MOD - 2, MOD)
	res *= finv[N - chi[v]]
	res %= MOD
	for nv in G[v]:
		if nv == pv:
			continue
		res *= finv[chi[nv]] * st[nv]
		res %= MOD
	rt[v] = res
	for nv in G[v]:
		if nv == pv:
			continue
		dfs2(nv, v)
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
st = [-1] * N
rt = [-1] * N
chi = [-1] * N
dfs1(0, -1)
rt[0] = st[0]
for nv in G[0]:
	dfs2(nv, 0)
for rt_i in rt:
	print(rt_i)


n = int(input())
F = n + 5
mod = 10 ** 9 + 7
fact = [1] * F
inv = [1] * F
for i in range(2, F):
	fact[i] = fact[i - 1] * i % mod
inv[F - 1] = pow(fact[F - 1], mod - 2, mod)
for i in range(F - 2, 1, -1):
	inv[i] = inv[i + 1] * (i + 1) % mod
invnum = [fact[i - 1] * inv[i] for i in range(n)]
graph = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
stack = [0]
order = [0]
parent = [-1] * n
comb = [0] * n
size = [1] * n
while stack:
	node = stack.pop()
	for neib in graph[node]:
		if neib != parent[node]:
			stack.append(neib)
			order.append(neib)
			parent[neib] = node
for node in order[n - 1:0:-1]:
	size[parent[node]] += size[node]
comb[0] = fact[n - 1]
for node in range(1, n):
	comb[0] *= invnum[size[node]]
	comb[0] %= mod
for node in order[1:]:
	comb[node] = comb[parent[node]] * size[node] * invnum[n - size[node]] % mod
print(*comb, sep='\n')


import sys
from collections import defaultdict
from functools import lru_cache
MOD = 1000000007

@lru_cache(maxsize=None)
def div(a, b):
	return a * pow(b, MOD - 2, MOD) % MOD

class Combination(object):

	def __init__(self, N, mod=MOD):
		(fac, finv, inv) = ([0] * (N + 1), [0] * (N + 1), [0] * (N + 1))
		fac[:2] = (1, 1)
		finv[:2] = (1, 1)
		inv[1] = 1
		for i in range(2, N + 1):
			fac[i] = fac[i - 1] * i % mod
			inv[i] = -inv[mod % i] * (mod // i) % mod
			finv[i] = finv[i - 1] * inv[i] % mod
		self.N = N
		self.MOD = mod
		self.fac = fac
		self.finv = finv
		self.inv = inv

	def __call__(self, n, k):
		if n < k:
			return 0
		if n < 0 or k < 0:
			return 0
		b = self.finv[k] * self.finv[n - k] % self.MOD
		return self.fac[n] * b % self.MOD

def solve(N: int, a: 'List[int]', b: 'List[int]'):
	E = [[] for _ in range(N)]
	for (aa, bb) in zip(a, b):
		E[aa - 1].append(bb - 1)
		E[bb - 1].append(aa - 1)
	cmb = Combination(N)
	curr = -1
	downward = [0]
	parent = [-1] * N
	while len(downward) < N:
		curr += 1
		v = downward[curr]
		for u in E[v]:
			if u == parent[v]:
				continue
			parent[u] = v
			downward.append(u)
	dp = [1] * N
	size = [0] * N
	for v in reversed(downward):
		for u in E[v]:
			if u == parent[v]:
				continue
			size[v] += size[u] + 1
			dp[v] *= cmb.finv[size[u] + 1]
			dp[v] %= MOD
			dp[v] *= dp[u]
			dp[v] %= MOD
		dp[v] *= cmb.fac[size[v]]
		dp[v] %= MOD
	for v in downward:
		for u in E[v]:
			if u == parent[v]:
				continue
			dp[u] = dp[v]
			dp[u] *= (size[u] + 1) * cmb.inv[N - (size[u] + 1)]
			dp[u] %= MOD
	for v in dp:
		print(v)
	return

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	a = [int()] * (N - 1)
	b = [int()] * (N - 1)
	for i in range(N - 1):
		a[i] = int(next(tokens))
		b[i] = int(next(tokens))
	solve(N, a, b)
main()


from collections import deque
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
mod = 10 ** 9 + 7
fact = [1] * (N + 1)
fact_inv = [1] * (N + 1)
for i in range(1, N + 1):
	fact[i] = fact[i - 1] * i % mod
fact_inv[-1] = pow(fact[-1], mod - 2, mod)
for i in range(N, 0, -1):
	fact_inv[i - 1] = fact_inv[i] * i % mod
g = [deque([]) for _ in range(N + 1)]
for (a, b) in ab:
	g[a].append(b)
	g[b].append(a)
parents = [0] * (N + 1)
q = deque([])
s = deque([1])
while s:
	x = s.pop()
	q.append(x)
	for y in g[x]:
		if y == parents[x]:
			continue
		else:
			parents[y] = x
			s.append(y)
q = list(q)
size_forward = [0] * (N + 1)
dp_forward = [1] * (N + 1)
for i in q[::-1]:
	p = parents[i]
	s = size_forward[i] + 1
	size_forward[p] += s
	dp_forward[i] *= fact[size_forward[i]]
	dp_forward[p] *= dp_forward[i] * fact_inv[s]
	dp_forward[p] %= mod
size_back = [N - 1 - i for i in size_forward]
dp_back = [1] * (N + 1)
for i in q[1:]:
	p = parents[i]
	x = dp_back[p]
	x *= fact_inv[size_back[p]]
	x *= dp_forward[p]
	x *= fact_inv[size_forward[p]]
	x *= fact[size_forward[i] + 1]
	x *= pow(dp_forward[i], mod - 2, mod)
	x *= fact[size_back[i] - 1]
	dp_back[i] = x % mod
for (a, b, c, d) in zip(size_forward[1:], dp_forward[1:], size_back[1:], dp_back[1:]):
	ans = b * d * fact[a + c] * fact_inv[a] * fact_inv[c]
	ans %= mod
	print(ans)


MOD = 1000000007
M = 2 * 10 ** 5 + 10
fact = [1] * M
ifact = [1] * M
for i in range(2, M):
	fact[i] = fact[i - 1] * i % MOD
ifact[M - 1] = pow(fact[M - 1], MOD - 2, MOD)
for i in range(2, M - 1)[::-1]:
	ifact[i] = ifact[i + 1] * (i + 1) % MOD

def comb(n, k):
	if n < 0 or k > n:
		return 0
	return fact[n] * ifact[k] % MOD * ifact[n - k] % MOD

class DP:

	def __init__(self, dp=1, size=0):
		self.dp = dp
		self.size = size

	def __add__(self, other):
		dp = self.dp
		dp *= other.dp
		dp %= MOD
		size = self.size + other.size
		dp *= comb(size, self.size)
		dp %= MOD
		return DP(dp, size)

	def __sub__(self, other):
		size = self.size - other.size
		dp = self.dp
		dp *= pow(comb(self.size, size), MOD - 2, MOD)
		dp %= MOD
		dp *= pow(other.dp, MOD - 2, MOD)
		dp %= MOD
		return DP(dp, size)

	def addRoot(self):
		return DP(self.dp, self.size + 1)
N = int(input())
e = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = [v - 1 for v in map(int, input().split())]
	e[a].append(b)
	e[b].append(a)
order = []
parent = [-1] * N
stack = [0]
while stack:
	v = stack.pop()
	order.append(v)
	for c in e[v]:
		if c == parent[v]:
			continue
		stack.append(c)
		parent[c] = v
dp = [DP() for _ in range(N)]
for v in order[::-1]:
	if parent[v] == -1:
		continue
	dp[parent[v]] += dp[v].addRoot()
for v in order[1:]:
	d = dp[parent[v]] - dp[v].addRoot()
	dp[v] += d.addRoot()
for d in dp:
	print(d.dp)


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
mod = 10 ** 9 + 7
n_max = 2 * 10 ** 5 + 1
(F, FI) = ([0] * (n_max + 1), [0] * (n_max + 1))
(F[0], FI[0]) = (1, 1)
for i in range(n_max):
	F[i + 1] = F[i] * (i + 1) % mod
FI[n_max - 1] = pow(F[n_max - 1], mod - 2, mod)
for i in reversed(range(n_max - 1)):
	FI[i] = FI[i + 1] * (i + 1) % mod

def comb(x, y):
	return F[x] * FI[x - y] * FI[y] % mod

def I(x):
	return pow(x, mod - 2, mod)
edge = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
Ans = []
inf = 10 ** 6
Par = [inf] * n
Par[0] = -1
Deg = [0] * n
Deg[0] = 0
Chk = [0]
while Chk:
	c = Chk.pop()
	for next in edge[c]:
		if Par[next] == inf:
			Par[next] = c
			Deg[next] += 1
			Chk.append(next)
from collections import deque
TS = list((v for v in range(n) if Deg[v] == 0))
D = deque(TS)
while D:
	v = D.popleft()
	for t in edge[v]:
		if t != Par[v]:
			Deg[t] -= 1
			if Deg[t] == 0:
				D.append(t)
				TS.append(t)
Used = [False] * n
C = [0] * n
for i in reversed(range(n)):
	v = TS[i]
	Used[v] = True
	for g in edge[v]:
		if not Used[g]:
			C[g] += C[v] + 1
D = [1] * n
for i in reversed(range(n)):
	v = TS[i]
	D[v] = D[v] * F[C[v]] % mod
	if Par[v] != -1:
		D[Par[v]] = D[Par[v]] * I(F[C[v] + 1]) * D[v] % mod
E = [1] * n
for i in range(n):
	v = TS[i]
	if Par[v] != -1:
		cur = E[v] * FI[n - C[v] - 1]
	else:
		cur = 1
	for e in edge[v]:
		if e != Par[v]:
			cur = cur * FI[C[e] + 1] * D[e] % mod
	for e in edge[v]:
		if e != Par[v]:
			E[e] = cur * F[n - 2 - C[e]] * F[C[e] + 1] * I(D[e]) % mod
for i in range(n):
	print(comb(n - 1, C[i]) * D[i] * E[i] % mod)


import sys
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
n = ni()
g = []
for i in range(n):
	g.append([])
for i in range(n - 1):
	(x, y) = na()
	x -= 1
	y -= 1
	g[x].append(y)
	g[y].append(x)
dp = [0] * n
ep = [0] * n
des = [0] * n

def enumfif(n, mod):
	f = [0] * (n + 1)
	invf = [0] * (n + 1)
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % mod
	a = f[n]
	b = mod
	(p, q) = (1, 0)
	while b > 0:
		c = a // b
		d = a
		a = b
		b = d % b
		d = p
		p = q
		q = d - c * q
	invf[n] = p + mod if p < 0 else p
	for i in range(n - 1, -1, -1):
		invf[i] = invf[i + 1] * (i + 1) % mod
	return (f, invf)

def C(n, r, mod, fif):
	if n < 0 or r < 0 or r > n:
		return 0
	return fif[0][n] * fif[1][r] * fif[1][n - r] % mod
mod = 1000000007
fif = enumfif(200005, mod)
sys.setrecursionlimit(200005)

def dfs(cur, pre, g):
	val = 1
	de = 0
	for e in g[cur]:
		if e == pre:
			continue
		dfs(e, cur, g)
		de += des[e]
		val = val * dp[e] * C(de, des[e], mod, fif) % mod
	dp[cur] = val
	des[cur] = de + 1

def dfs2(cur, pre, g):
	for e in g[cur]:
		if e == pre:
			continue
		val = dp[cur] * fif[1][n - 1] * fif[0][n - des[e] - 1] * fif[0][des[e]] % mod
		dp[e] = val * C(n - 1, n - des[e], mod, fif) % mod
		dfs2(e, cur, g)

def invl(a, mod):
	b = mod
	p = 1
	q = 0
	while b > 0:
		c = a // b
		(a, b) = (b, a % b)
		(p, q) = (q, p - c * q)
	return p + mod if p < 0 else p
dfs(0, -1, g)
dfs2(0, -1, g)
for val in dp:
	print(val)


from functools import reduce

def rerooting(n, edges, identity, merge, add_node):
	from functools import reduce
	G = [[] for _ in range(n)]
	for (a, b) in edges:
		G[a].append(b)
		G[b].append(a)
	parents = [0] * n
	order = []
	stack = [0]
	parents[0] = -1
	while stack:
		v = stack.pop()
		p = parents[v]
		order.append(v)
		for u in G[v]:
			if p != u:
				stack.append(u)
				parents[u] = v
	dp_down = [0] * n
	for v in order[:0:-1]:
		p = parents[v]
		dp_down[v] = add_node(reduce(merge, (dp_down[u] for u in G[v] if u != p), identity), v)
	dp_up = [identity] * n
	for v in order:
		Gv = G[v]
		if len(Gv) == 1 and v != 0:
			continue
		p = parents[v]
		cum = identity
		right = [identity]
		for u in Gv[::-1]:
			if u != p:
				cum = merge(dp_down[u], cum)
				right.append(cum)
		cum = dp_up[v]
		idx_right = -2
		for u in Gv:
			if u != p:
				dp_up[u] = add_node(merge(cum, right[idx_right]), v)
				idx_right -= 1
				cum = merge(cum, dp_down[u])
	results = [add_node(merge(reduce(merge, (dp_down[u] for u in Gv if u != parents[v]), identity), dp_up[v]), v) for (v, Gv) in enumerate(G)]
	return results

class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		f = 1
		self.fac = fac = [f]
		for i in range(1, n_max + 1):
			f = f * i % mod
			fac.append(f)
		f = pow(f, mod - 2, mod)
		self.facinv = facinv = [f]
		for i in range(n_max, 0, -1):
			f = f * i % mod
			facinv.append(f)
		facinv.reverse()

	def __call__(self, n, r):
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

def main():
	N = int(input())
	AB = [list([int(x) - 1 for x in input().split()]) for _ in range(N - 1)]
	mod = 10 ** 9 + 7
	comb = Combination(202020)
	identity = (1, 0)
	(fac, facinv) = (comb.fac, comb.facinv)

	def merge(a, b):
		(a0, a1) = a
		(b0, b1) = b
		return (a0 * b0 * fac[a1 + b1] * facinv[a1] * facinv[b1] % mod, a1 + b1)

	def add_node(a, idx):
		(a0, a1) = a
		return (a0, a1 + 1)
	Ans = rerooting(N, AB, identity, merge, add_node)
	print('\n'.join((str(ans) for (ans, _) in Ans)))
main()


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from collections import deque
MOD = 10 ** 9 + 7
N = int(input())
tree = dict(zip(range(N), [[] for i in range(N)]))
edge_id = {}
c = 0
for i in range(N - 1):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	tree[a].append(b)
	tree[b].append(a)
	edge_id[a, b] = c
	edge_id[b, a] = c + 1
	c += 2
size = [0] * 2 * (N - 1)

def calc_size(v1, v2):
	global size
	idx = edge_id[v1, v2]
	if size[idx]:
		return size[idx]
	children = tree[v2]
	s = 1
	for child in children:
		if child == v1:
			continue
		s += calc_size(v2, child)
	size[idx] = s
	idx_inv = edge_id[v2, v1]
	size[idx_inv] = N - s
	return s
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10 ** 9 + 7
for i in range(2, 2 * 10 ** 5 + 1):
	g1.append(g1[-1] * i % MOD)
	inverse.append(-inverse[MOD % i] * (MOD // i) % MOD)
	g2.append(g2[-1] * inverse[-1] % MOD)

def comb(n, r, mod=MOD):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
ans = [0] * N
dp = [0] * 2 * (N - 1)

def calc_dp(v1, v2):
	global dp
	idx = edge_id[v1, v2]
	if dp[idx]:
		return dp[idx]
	children = tree[v2]
	s = calc_size(v1, v2)
	res = g1[s - 1]
	for child in children:
		if child == v1:
			continue
		res *= calc_dp(v2, child)
		res %= MOD
		_s = calc_size(v2, child)
		res *= g2[_s]
		res %= MOD
	dp[idx] = res
	return res

def calc_ans(i):
	global ans
	global dp
	if ans[i]:
		return ans[i]
	children = tree[i]
	res = g1[N - 1]
	for child in children:
		res *= calc_dp(i, child)
		res %= MOD
		_s = calc_size(i, child)
		res *= g2[_s]
		res %= MOD
	ans[i] = res
	return res
calc_ans(0)
d = deque([[0, -1]])
c = 0
while d:
	(node, par) = d.popleft()
	c += 1
	children = tree[node]
	for child in children:
		if child == par:
			continue
		s1 = calc_size(node, child)
		s2 = N - s1
		r = g1[s1] * g1[s2 - 1] % MOD * (g2[s1 - 1] * g2[s2] % MOD) % MOD
		ans[child] = ans[node] * r % MOD
		d.append([child, node])
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def solve():
	MOD = 10 ** 9 + 7
	N = int(input())
	adjL = [[] for _ in range(N)]
	for _ in range(N - 1):
		(a, b) = list(map(int, input().split()))
		(a, b) = (a - 1, b - 1)
		adjL[a].append(b)
		adjL[b].append(a)

	def getInvs(n, MOD):
		invs = [1] * (n + 1)
		for x in range(2, n + 1):
			invs[x] = -(MOD // x) * invs[MOD % x] % MOD
		return invs
	invs = getInvs(N, MOD)
	dp = [[] for _ in range(N)]
	outdegs = [0] * N
	sizes = [0] * N
	iPars = [-1] * N

	def dfsDP(v, vPar):
		outdeg = outdegs[v] = len(adjL[v])
		dp[v] = [0] * outdeg
		res = 1
		sizes[v] = 1
		for (i, v2) in enumerate(adjL[v]):
			if v2 == vPar:
				iPars[v] = i
				continue
			dp[v][i] = dfsDP(v2, v)
			res = res * dp[v][i] % MOD
			sizes[v] += sizes[v2]
		return res * invs[sizes[v]] % MOD
	anss = [0] * N

	def dfsAns(v, vPar, resPar):
		if vPar != -1:
			dp[v][iPars[v]] = resPar
		outdeg = outdegs[v]
		dpL = [1] * (outdeg + 1)
		for i in range(outdeg):
			v2 = adjL[v][i]
			dpL[i + 1] = dpL[i] * dp[v][i] % MOD
		dpR = [1] * (outdeg + 1)
		for i in reversed(list(range(outdeg))):
			v2 = adjL[v][i]
			dpR[i] = dpR[i + 1] * dp[v][i] % MOD
		anss[v] = dpL[-1] * invs[N]
		for (i, v2) in enumerate(adjL[v]):
			if v2 == vPar:
				continue
			dfsAns(v2, v, dpL[i] * dpR[i + 1] * invs[N - sizes[v2]] % MOD)
	dfsDP(0, -1)
	dfsAns(0, -1, 0)

	def getFact(n, MOD):
		fact = 1
		for i in range(1, n + 1):
			fact = fact * i % MOD
		return fact
	factN = getFact(N, MOD)
	for v in range(N):
		anss[v] = anss[v] * factN % MOD
	print('\n'.join(map(str, anss)))
solve()


n = int(input())
arr = [list(map(int, input().split())) for _ in range(n - 1)]
graph = [[] for _ in range(n)]
for (a, b) in arr:
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
mod = 10 ** 9 + 7
fac = [1] * (n + 1)
inv = [1] * (n + 1)
ifac = [1] * (n + 1)
for i in range(2, n + 1):
	fac[i] = fac[i - 1] * i % mod
	inv[i] = -(mod // i) * inv[mod % i] % mod
	ifac[i] = ifac[i - 1] * inv[i] % mod
parents = [-1] * n
children = [[] for _ in range(n)]
orders = []
stack = [0]
flags = [True] * n
flags[0] = False
while stack:
	tmp = stack.pop()
	orders.append(tmp)
	for node in graph[tmp]:
		if flags[node]:
			flags[node] = False
			children[tmp].append(node)
			stack.append(node)
			parents[node] = tmp
size = [1] * n
dp = [1] * n
for parent in orders[::-1]:
	for child in children[parent]:
		size[parent] += size[child]
		dp[parent] = dp[parent] * dp[child] * ifac[size[child]] % mod
	dp[parent] = dp[parent] * fac[size[parent] - 1] % mod
size2 = [n - i + 1 for i in size]
dp2 = [1] * n
dp2[0] = dp[0]
for parent in orders[1:]:
	child = parents[parent]
	dp2[parent] = dp2[parent] * size[parent] * dp2[child] * inv[size2[parent] - 1] % mod
for i in range(n):
	print(dp2[i])


import sys
sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7

def prepare(n):
	global MOD
	modFacts = [0] * (n + 1)
	modFacts[0] = 1
	for i in range(n):
		modFacts[i + 1] = modFacts[i] * (i + 1) % MOD
	invs = [1] * (n + 1)
	invs[n] = pow(modFacts[n], MOD - 2, MOD)
	for i in range(n, 1, -1):
		invs[i - 1] = invs[i] * i % MOD
	return (modFacts, invs)

def dfs(v):
	global MOD
	childs = 0
	var = 1
	for e in edge[v]:
		if path[e] == 0:
			path[e] = 1
			(nc, nvar) = dfs(e)
			childs += nc
			V[v][e] = (nc, nvar)
			var *= nvar
			var %= MOD
			var *= invs[nc]
			var %= MOD
	var *= modFacts[childs]
	var %= MOD
	dp[v] = (childs, var)
	return (childs + 1, var)

def dfs2(v, pn, pVar):
	global MOD
	(oNodes, oVar) = dp[v]
	tNodes = pn + oNodes
	tVar = oVar * pVar % MOD
	tVar *= invs[oNodes]
	tVar %= MOD
	tVar *= modFacts[tNodes]
	tVar %= MOD
	tVar *= invs[pn]
	tVar %= MOD
	dp[v] = (tNodes, tVar)
	for e in V[v].keys():
		(eNodes, eVar) = V[v][e]
		nVar = tVar * invs[tNodes] % MOD
		nVar *= modFacts[eNodes]
		nVar %= MOD
		nVar *= modFacts[tNodes - eNodes]
		nVar %= MOD
		nVar *= pow(eVar, MOD - 2, MOD)
		nVar %= MOD
		dfs2(e, tNodes - eNodes + 1, nVar)
N = int(input())
edge = [[] for _ in range(N)]
for s in sys.stdin.readlines():
	(a, b) = map(int, s.split())
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
(modFacts, invs) = prepare(N)
V = [{} for _ in range(N)]
path = [0] * N
dp = [None] * N
path[0] = 1
dfs(0)
dfs2(0, 0, 1)
for i in range(N):
	print(dp[i][1])


import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
	N = int(input())
	edge = [[] for _ in range(N + 1)]
	MOD = 10 ** 9 + 7
	fac = [0] * (N + 1)
	(fac[0], fac[1]) = (1, 1)
	invfac = [0] * (N + 1)
	(invfac[0], invfac[1]) = (1, 1)
	for i in range(2, N + 1):
		fac[i] = fac[i - 1] * i % MOD
	invfac[-1] = pow(fac[-1], MOD - 2, MOD)
	for i in range(N, 0, -1):
		invfac[i - 1] = invfac[i] * i % MOD
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		edge[a].append(b)
		edge[b].append(a)
	proc = []
	parent = [0] * (N + 1)
	q = deque([1])
	while q:
		now = q.pop()
		proc.append(now)
		for fol in edge[now]:
			if fol == parent[now]:
				continue
			parent[fol] = now
			q.append(fol)
	d_size = [0] * (N + 1)
	d_dp = [1] * (N + 1)
	for v in proc[::-1]:
		d_dp[v] *= fac[d_size[v]]
		d_dp[v] %= MOD
		p = parent[v]
		s = d_size[v] + 1
		d_size[p] += s
		d_dp[p] *= d_dp[v] * invfac[s]
		d_dp[p] %= MOD
	u_size = [N - num - 1 for num in d_size]
	u_dp = [1] * (N + 1)
	for v in proc[1:]:
		p = parent[v]
		x = d_dp[p]
		x *= u_dp[p]
		x *= invfac[d_size[p]]
		x *= fac[d_size[v] + 1]
		x *= pow(d_dp[v], MOD - 2, MOD)
		x %= MOD
		x *= fac[u_size[v] - 1]
		x *= invfac[u_size[p]]
		u_dp[v] = x % MOD
	u_size[1] = 0
	u_dp[1] = 1
	for i in range(1, N + 1):
		ret = d_dp[i] * u_dp[i] * fac[d_size[i] + u_size[i]] * invfac[d_size[i]] * invfac[u_size[i]] % MOD
		print(ret)
main()


import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7

def MOD_inv(a):
	b = MOD
	u = 1
	v = 0
	while b > 0:
		t = a // b
		a -= t * b
		(a, b) = (b, a)
		u -= t * v
		(u, v) = (v, u)
	u = u % MOD
	if u < 0:
		u += MOD
	return u

def init_Graph(G):
	for _ in range(len(G) - 1):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		G[a].append(b)
		G[b].append(a)

def dfs(G, dp, t, perm, crr, pre):
	tmp = 1
	f = False
	for nxt in G[crr]:
		if nxt == pre:
			continue
		dfs(G, dp, t, perm, nxt, crr)
		t[crr] += t[nxt]
		tmp *= dp[nxt]
		f = True
	if f:
		dp[crr] = perm[t[crr] - 1]
		for nxt in G[crr]:
			if nxt == pre:
				continue
			dp[crr] *= MOD_inv(perm[t[nxt]]) * dp[nxt]
			dp[crr] %= MOD
	else:
		dp[crr] = 1

def solve(G, dp, t, perm, crr, pre, mul):
	dp[crr] *= MOD_inv(perm[t[crr] - 1]) * perm[len(G) - 1] * mul
	dp[crr] %= MOD
	for nxt in G[crr]:
		if nxt == pre:
			continue
		crr_t = len(G)
		crr_t -= t[nxt]
		crr_dp = dp[crr]
		crr_dp *= perm[t[nxt]] * MOD_inv(perm[len(G) - 1]) * perm[len(G) - t[nxt] - 1] * MOD_inv(dp[nxt])
		crr_dp %= MOD
		tmp = MOD_inv(perm[crr_t]) * crr_dp % MOD
		solve(G, dp, t, perm, nxt, crr, tmp)

def main():
	n = int(input())
	G = [[] for _ in range(n)]
	init_Graph(G)
	t = [1] * n
	dp = [0] * n
	perm = [1] * (2 * 10 ** 5 + 10)
	for i in range(2, 2 * 10 ** 5 + 10):
		perm[i] = perm[i - 1] * i % MOD
	dfs(G, dp, t, perm, 0, -1)
	solve(G, dp, t, perm, 0, -1, 1)
	for v in dp:
		print(v)
main()


import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, n, mod):
		self.f = [1]
		self.mod = mod
		for j in range(1, n + 1):
			self.f.append(self.f[-1] * j % mod)
		self.i = [pow(self.f[-1], mod - 2, mod)]
		for j in range(n, 0, -1):
			self.i.append(self.i[-1] * j % mod)
		self.i.reverse()

	def factorial(self, j):
		return self.f[j]

	def ifactorial(self, j):
		return self.i[j]

	def comb(self, n, k):
		return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0
N = int(input())
G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	G[a].append(b)
	G[b].append(a)
F = Factorial(N + 2, MOD)
root = 1
stack = [root]
check = [False] * (N + 1)
check[root] = True
p = [0] * (N + 1)
DAG = []
while stack:
	now_ = stack.pop()
	DAG.append(now_)
	for next_ in G[now_]:
		if check[next_]:
			continue
		stack.append(next_)
		check[next_] = True
		p[next_] = now_
size1 = [0] * (N + 1)
dp1 = [1] * (N + 1)
for now_ in DAG[::-1]:
	size1[now_] += 1
	size1[p[now_]] += size1[now_]
	dp1[now_] *= F.factorial(size1[now_] - 1)
	dp1[now_] %= MOD
	dp1[p[now_]] *= dp1[now_] * F.ifactorial(size1[now_])
	dp1[p[now_]] %= MOD
size2 = [N - size1[i] + 1 for i in range(N + 1)]
dp2 = [1] * (N + 1)
for i in DAG:
	parent = i
	for now_ in G[i]:
		if now_ == p[i]:
			continue
		x = dp1[parent]
		x *= F.ifactorial(size1[parent] - 1)
		x *= F.factorial(size1[now_])
		x *= pow(dp1[now_], MOD - 2, MOD)
		x *= dp2[parent]
		x *= F.ifactorial(size2[parent] - 1)
		x *= F.factorial(size2[now_] - 2)
		dp2[now_] = x % MOD
for i in range(1, N + 1):
	ans = dp1[i] * F.ifactorial(size1[i] - 1) * dp2[i] * F.ifactorial(size2[i] - 1) * F.factorial(N - 1)
	print(ans % MOD)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def solve():
	MOD = 10 ** 9 + 7
	N = int(input())
	adjL = [[] for _ in range(N)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		adjL[a].append(b)
		adjL[b].append(a)

	def getFacts(n, MOD):
		facts = [1] * (n + 1)
		for x in range(2, n + 1):
			facts[x] = facts[x - 1] * x % MOD
		return facts
	facts = getFacts(N, MOD)

	def getInvFacts(n, MOD):
		invFacts = [0] * (n + 1)
		invFacts[n] = pow(facts[n], MOD - 2, MOD)
		for x in reversed(range(n)):
			invFacts[x] = invFacts[x + 1] * (x + 1) % MOD
		return invFacts
	invFacts = getInvFacts(N, MOD)

	def getComb(n, k, MOD):
		if n < k:
			return 0
		return facts[n] * invFacts[k] * invFacts[n - k] % MOD
	dp = [1] * N
	sizes = [0] * N

	def dfsDP(v, vPar):
		sizes[v] = 0
		for v2 in adjL[v]:
			if v2 == vPar:
				continue
			dp[v] = dp[v] * dfsDP(v2, v) % MOD
			sizes[v] += sizes[v2]
			dp[v] = dp[v] * getComb(sizes[v], sizes[v2], MOD) % MOD
		sizes[v] += 1
		return dp[v]
	anss = [0] * N

	def dfsAns(v, vPar, resPar):
		anss[v] = dp[v] * resPar * getComb(N - 1, sizes[v] - 1, MOD) % MOD
		for v2 in adjL[v]:
			if v2 == vPar:
				continue
			coef = dp[v2] * getComb(N - 1, sizes[v2], MOD) % MOD
			dfsAns(v2, v, anss[v] * pow(coef, MOD - 2, MOD) % MOD)
	dfsDP(0, -1)
	dfsAns(0, -1, 1)
	print('\n'.join(map(str, anss)))
solve()


import sys
sys.setrecursionlimit(10 ** 6)
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(stdin.readline().rstrip())
nm = lambda : map(int, stdin.readline().split())
nl = lambda : list(map(int, stdin.readline().split()))
n_ = 2 * 10 ** 5 + 20
mod = 10 ** 9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
	fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
	rev[i] = rev[i + 1] * (i + 1) % mod

def modinv(x, mod):
	x %= mod
	(a, b) = (x, mod)
	(u, v) = (1, 0)
	while b:
		t = a // b
		a -= t * b
		(a, b) = (b, a)
		u -= t * v
		(u, v) = (v, u)
	return u % mod

def nCr(n, r):
	if r > n:
		return 0
	return fun[n] * rev[r] % mod * rev[n - r] % mod
n = ni()
g = [list() for _ in range(n)]
for _ in range(n - 1):
	(a, b) = nm()
	a -= 1
	b -= 1
	g[a].append(b)
	g[b].append(a)
sl = [1] * n
pm = [1] * n

def dfs(v, p):
	for x in g[v]:
		if x == p:
			continue
		dfs(x, v)
		sl[v] += sl[x]
		pm[v] = pm[v] * pm[x] % mod
	sv = sl[v] - 1
	for x in g[v]:
		if x == p:
			continue
		pm[v] = pm[v] * nCr(sv, sl[x]) % mod
		sv -= sl[x]
	return

def dfs2(v, p):
	pp = pm[p] * modinv(nCr(n - 1, sl[v]) * pm[v], mod) % mod
	sp = n - sl[v]
	pm[v] = pm[v] * pp % mod * nCr(n - 1, sp) % mod
	for x in g[v]:
		if x == p:
			continue
		dfs2(x, v)
dfs(0, -1)
for x in g[0]:
	dfs2(x, 0)
print(*pm, sep='\n')


import sys
input = sys.stdin.buffer.readline

class Combination:

	def __init__(self, size, mod=10 ** 9 + 7):
		self.size = size + 2
		self.mod = mod
		self.fact = [1, 1] + [0] * size
		self.factInv = [1, 1] + [0] * size
		self.inv = [0, 1] + [0] * size
		for i in range(2, self.size):
			self.fact[i] = self.fact[i - 1] * i % self.mod
			self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
			self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

	def npr(self, n, r):
		if n < r or n < 0 or r < 0:
			return 0
		return self.fact[n] * self.factInv[n - r] % self.mod

	def ncr(self, n, r):
		if n < r or n < 0 or r < 0:
			return 0
		return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

	def nhr(self, n, r):
		return self.ncr(n + r - 1, n - 1)

	def factN(self, n):
		if n < 0:
			return 0
		return self.fact[n]

	def factInvN(self, n):
		if n < 0:
			return 0
		return self.factInv[n]
N = int(input())
MOD = 10 ** 9 + 7
comb = Combination(N + 100)
edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(fr, to) = map(int, input().split())
	edges[fr].append(to)
	edges[to].append(fr)
order = []
parent = [0] * (N + 1)
st = [1]
while st:
	now = st.pop()
	order.append(now)
	for to in edges[now]:
		if to == parent[now]:
			continue
		st.append(to)
		parent[to] = now
size = [1] * (N + 1)
for v in order[::-1]:
	size[parent[v]] += size[v]
dpLeaf = [1] * (N + 1)
for v in order[::-1]:
	pr = parent[v]
	dpLeaf[v] = dpLeaf[v] * comb.factN(size[v] - 1) % MOD
	dpLeaf[pr] = dpLeaf[pr] * dpLeaf[v] * comb.factInvN(size[v]) % MOD
ans = [0] * (N + 1)
ans[1] = dpLeaf[1]
for v in order[1:]:
	pr = parent[v]
	ans[v] = ans[pr] * comb.factN(N - 1 - size[v]) * comb.factInvN(N - size[v]) * size[v] % MOD
print(*ans[1:], sep='\n')


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return list(map(int, input().split()))

def LIST():
	return list(map(int, input().split()))

def ZIP(n):
	return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
lim = N + 10
fact = [1] * (lim + 1)
fact_inv = [1] * (lim + 1)
for n in range(1, lim + 1):
	fact[n] = fact[n - 1] * n % mod
fact_inv[lim] = pow(fact[lim], mod - 2, mod)
for n in range(lim, 0, -1):
	fact_inv[n - 1] = n * fact_inv[n] % mod
tree = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = MAP()
	tree[a].append(b)
	tree[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	x = stack.pop()
	order.append(x)
	for y in tree[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)
size_d = [0] * (N + 1)
dp_d = [1] * (N + 1)
for v in order[::-1]:
	dp_d[v] *= fact[size_d[v]]
	dp_d[v] %= mod
	p = parent[v]
	s = size_d[v] + 1
	size_d[p] += s
	dp_d[p] *= fact_inv[s] * dp_d[v]
	dp_d[p] %= mod
size_u = [N - 1 - x for x in size_d]
dp_u = [1] * (N + 1)

def merge(p1, p2):
	(den_inv1, v1) = p1
	(den_inv2, v2) = p2
	return (den_inv1 * den_inv2 % mod, v1 * v2 % mod)
for v in order:
	p = parent[v]
	arr = [(fact_inv[size_d[node] + 1], dp_d[node]) if node != p else (fact_inv[size_u[v]], dp_u[v]) for node in tree[v]]
	left = [(1, 1)] + list(accumulate(arr, merge))[:-1]
	right = list(accumulate(arr[::-1], merge))[-2::-1] + [(1, 1)]
	contrib = [merge(x, y) for (x, y) in zip(left, right)]
	for (node, c) in zip(tree[v], contrib):
		if node != p:
			dp_u[node] = c[0] * c[1] * fact[size_u[node] - 1] % mod
for (xd, xu, sd, su) in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
	x = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % mod
	print(x)


def rerooting(n, edges, identity, merge, add_node):
	G = [[] for _ in range(n)]
	G_idxs = [[] for _ in range(n)]
	for (a, b) in edges:
		G_idxs[a].append(len(G[b]))
		G_idxs[b].append(len(G[a]))
		G[a].append(b)
		G[b].append(a)
	parents = [0] * n
	order = []
	stack = [0]
	parents[0] = -1
	while stack:
		v = stack.pop()
		p = parents[v]
		order.append(v)
		for u in G[v]:
			if p != u:
				stack.append(u)
				parents[u] = v
	subtree_res = [[0] * len(Gv) for Gv in G]
	for v in order[:0:-1]:
		p = parents[v]
		result = identity
		for (idx_Gv, (u, subtree_res_v_i)) in enumerate(zip(G[v], subtree_res[v])):
			if p == u:
				parent_idx = idx_Gv
			else:
				result = merge(result, subtree_res_v_i)
		idx_p2v = G_idxs[v][parent_idx]
		subtree_res[p][idx_p2v] = add_node(result, v)
	results = [0] * n
	for v in order:
		subtree_res_v = subtree_res[v]
		cum = identity
		cum_from_tail = [identity]
		for r in subtree_res_v[:0:-1]:
			cum = merge(r, cum)
			cum_from_tail.append(cum)
		cum_from_tail.reverse()
		cum = identity
		for (r, cum_t, u, idx_u2v) in zip(subtree_res_v, cum_from_tail, G[v], G_idxs[v]):
			result = add_node(merge(cum, cum_t), v)
			subtree_res[u][idx_u2v] = result
			cum = merge(cum, r)
		results[v] = add_node(cum, v)
	return results

class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		f = 1
		self.fac = fac = [f]
		for i in range(1, n_max + 1):
			f = f * i % mod
			fac.append(f)
		f = pow(f, mod - 2, mod)
		self.facinv = facinv = [f]
		for i in range(n_max, 0, -1):
			f = f * i % mod
			facinv.append(f)
		facinv.reverse()

	def __call__(self, n, r):
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

def main():
	N = int(input())
	AB = [list([int(x) - 1 for x in input().split()]) for _ in range(N - 1)]
	mod = 10 ** 9 + 7
	comb = Combination(202020)
	identity = (1, 0)
	merge = lambda a, b: (a[0] * b[0] % mod * comb(a[1] + b[1], a[1]) % mod, a[1] + b[1])
	add_node = lambda value, idx: (value[0], value[1] + 1)
	Ans = rerooting(N, AB, identity, merge, add_node)
	print('\n'.join((str(ans) for (ans, _) in Ans)))
main()


import sys
input = sys.stdin.readline

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return list(map(int, input().split()))

def main():
	mod = 10 ** 9 + 7
	N = I()
	fact = [1, 1]
	factinv = [1, 1]
	inv = [0, 1]
	for i in range(2, 2 * N + 10):
		fact.append(fact[-1] * i % mod)
		inv.append(-inv[mod % i] * (mod // i) % mod)
		factinv.append(factinv[-1] * inv[-1] % mod)
	adj = [[] for _ in range(N)]
	for i in range(N - 1):
		(a, b) = MI()
		a -= 1
		b -= 1
		adj[a].append(b)
		adj[b].append(a)
	import queue
	P = [-1] * N
	Q = queue.Queue()
	R = []
	Q.put(0)
	while not Q.empty():
		v = Q.get()
		R.append(v)
		for nv in adj[v]:
			if nv != P[v]:
				P[nv] = v
				adj[nv].remove(v)
				Q.put(nv)
	size1 = [1] * N
	size2 = [0] * N
	dp1 = [1] * N
	dp2 = [1] * N
	for v in R[1:][::-1]:
		size1[P[v]] += size1[v]
	for v in range(N):
		size2[v] = N - size1[v]
	for v in R[1:][::-1]:
		dp1[v] = dp1[v] * fact[size1[v] - 1] % mod
		p = P[v]
		dp1[p] = dp1[p] * dp1[v] * factinv[size1[v]] % mod
	dp1[R[0]] = dp1[R[0]] * fact[size1[R[0]] - 1] % mod
	for v in R[1:]:
		p = P[v]
		temp = dp2[p]
		temp2 = dp1[p] * pow(dp1[v], mod - 2, mod) % mod
		temp = temp * temp2 % mod
		temp = temp * factinv[size1[p] - 1] * fact[size1[v]] % mod
		temp = temp * factinv[size2[p]] * fact[size2[v] - 1] % mod
		dp2[v] = temp
	for i in range(N):
		ans = dp1[i] * dp2[i] * fact[N - 1] * factinv[size1[i] - 1] * factinv[size2[i]] % mod
		print(ans)
main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
mod = 10 ** 9 + 7

class PERM_COMB_MOD:

	def __init__(self, max_n=510000, mod=10 ** 9 + 7):
		self.fac = [0] * max_n
		self.finv = [0] * max_n
		self.inv = [0] * max_n
		self.fac[0] = self.fac[1] = 1
		self.finv[0] = self.finv[1] = 1
		self.inv[1] = 1
		self.max = max_n
		self.mod = mod
		self._maesyori()

	def _maesyori(self):
		for i in range(2, self.max):
			self.fac[i] = self.fac[i - 1] * i % self.mod
			self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
			self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod
n = int(input())
G = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	G[a].append(b)
	G[b].append(a)
PCM = PERM_COMB_MOD(2 * n)
root = n // 2
tmp = [[] for i in range(n)]
cost = [1] * n
size = [1] * n

def bfs1(root):
	rev = [(root, -1)]
	for i in range(n):
		(cur, par) = rev[i]
		for to in G[cur]:
			if to != par:
				rev.append((to, cur))
	for i in reversed(range(1, n)):
		(cur, par) = rev[i]
		size[par] += size[cur]
		if len(tmp[cur]) == 0:
			pass
		elif len(tmp[cur]) == 1:
			cost[cur] = tmp[cur][0]
		else:
			size_sum = 0
			inv_sum = 1
			count_sum = 1
			for to in G[cur]:
				if to != par:
					size_sum += size[to]
					inv_sum *= PCM.finv[size[to]]
					inv_sum %= mod
					count_sum *= cost[to]
					count_sum %= mod
			cost[cur] = PCM.fac[size_sum] * inv_sum * count_sum % mod
		tmp[par].append(cost[cur])
bfs1(root)
ans = [0] * n

def bfs2(root):
	rev = [(root, -1, 1)]
	for i in range(n):
		(cur, par, d_par) = rev[i]
		size_par = n - size[cur]
		size_sum = 0
		inv_sum = 1
		count_sum = 1
		for to in G[cur]:
			if to != par:
				size_sum += size[to]
				inv_sum *= PCM.finv[size[to]]
				count_sum *= cost[to]
			else:
				size_sum += size_par
				inv_sum *= PCM.finv[size_par]
				count_sum *= d_par
			inv_sum %= mod
			count_sum %= mod
		ans_i = PCM.fac[size_sum] * inv_sum * count_sum % mod
		ans[cur] = ans_i
		for to in G[cur]:
			if to == par:
				continue
			b = size[to]
			bb = cost[to]
			d_nxt = ans_i * PCM.fac[b] * pow(bb, mod - 2, mod) * PCM.fac[size_sum - b] * PCM.finv[size_sum] % mod
			rev.append((to, cur, d_nxt))
bfs2(root)
print(*ans, sep='\n')


n = int(input())
big = 1
mod = 10 ** 9 + 7
for i in range(1, n):
	big *= i
	big %= mod

def inv(x):
	y = 1
	while x != 1:
		y *= mod // x + 1
		y %= mod
		x -= mod % x
	return y
tribe = [1 for _ in range(n)]
we = [1 for _ in range(n)]
peer = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	peer[a].append(b)
	peer[b].append(a)
seen = [0 for _ in range(n)]
pre = [0 for _ in range(n)]
seen[0] = 1
rank = []
now = [0]
while now:
	rank.append(now)
	last = now
	now = []
	for x in last:
		for y in peer[x]:
			if seen[y] == 0:
				seen[y] = 1
				now.append(y)
				pre[y] = x
pre[0] = 10 ** 6
rank.reverse()
for z in rank:
	if z == [0]:
		continue
	for w in z:
		tribe[pre[w]] += tribe[w]
		we[pre[w]] *= tribe[w] * we[w]
		we[pre[w]] %= mod
rank.reverse()
for z in rank:
	if z == [0]:
		continue
	for w in z:
		tmp = we[pre[w]]
		tmp *= inv(we[w] * tribe[w] % mod)
		tmp *= n - tribe[w]
		we[w] *= tmp
		we[w] %= mod
for i in range(n):
	print(big * inv(we[i]) % mod)


(N, *L) = map(int, open(0).read().split())
MOD = 10 ** 9 + 7
graph = [[] for i in range(N + 1)]
for (a, b) in zip(*[iter(L)] * 2):
	graph[a].append(b)
	graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	x = stack.pop()
	order.append(x)
	for c in graph[x]:
		if parent[x] == c:
			continue
		stack.append(c)
		parent[c] = x
fact = [1] * (N + 10)
for n in range(1, N + 10):
	fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
	fact_inv[n - 1] = fact_inv[n] * n % MOD
dp_d = [1] * (N + 1)
size_d = [0] * (N + 1)
for v in order[::-1]:
	s = size_d[v]
	p = parent[v]
	dp_d[v] *= fact[s]
	dp_d[v] %= MOD
	m = dp_d[v]
	size_d[p] += s + 1
	dp_d[p] *= fact_inv[s + 1] * m
	dp_d[p] %= MOD
size_u = [N - 2 - x for x in size_d]
dp_u = [1] * (N + 1)
for v in order[1:]:
	p = parent[v]
	x = dp_d[p]
	x *= fact_inv[size_d[p]]
	x *= fact[size_d[v] + 1]
	x *= pow(dp_d[v], MOD - 2, MOD)
	x *= fact[size_u[v]]
	x *= fact_inv[size_u[p] + 1]
	x *= dp_u[p]
	dp_u[v] = x % MOD
for (xd, xu, sd, su) in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
	su += 1
	x = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % MOD
	print(x)


import sys
sys.setrecursionlimit(10 ** 6)
from collections import deque
MOD = 1000000007
N = int(input())
childs = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	childs[a].append(b)
	childs[b].append(a)
dp = [0] * (N + 1)
tree_size = [0] * (N + 1)
ans = [0] * (N + 1)
n_inv = [1, 1]
n_j_mod = [1, 1]
for i in range(2, N + 1):
	n_inv.append(pow(i, MOD - 2, MOD) * n_inv[-1] % MOD)
	n_j_mod.append(n_j_mod[-1] * i % MOD)

def dfs(i, father=-1):
	method_num = 1
	t_size = 1
	for child in childs[i]:
		if child != father:
			(num, size) = dfs(child, i)
			method_num = method_num * num * n_inv[size] % MOD
			t_size += size
	method_num = method_num * n_j_mod[t_size - 1] % MOD
	dp[i] = method_num
	tree_size[i] = t_size
	return (method_num, t_size)

def rdfs(i, f_num, father=-1):
	ans[i] = dp[i] * f_num * n_j_mod[N - 1] * n_inv[N - tree_size[i]] * n_inv[tree_size[i] - 1] % MOD
	for child in childs[i]:
		if child != father:
			cf_num = ans[i] * n_j_mod[tree_size[child]] * n_j_mod[N - tree_size[child] - 1] * n_inv[N - 1] * pow(dp[child], MOD - 2, MOD) % MOD
			rdfs(child, cf_num, i)
dfs(1)
rdfs(1, 1)
print('\n'.join(list(map(str, ans[1:]))))


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict, deque
from math import factorial
MOD = 10 ** 9 + 7

class Facts:

	def __init__(self, max_num=10 ** 5, p=10 ** 9 + 7):
		self.p = p
		self.max_num = max_num
		self.fact = [1] * (self.max_num + 1)
		for i in range(1, self.max_num + 1):
			self.fact[i] = self.fact[i - 1] * i
			self.fact[i] %= self.p

	def power_func(self, a, b):
		ans = 1
		while b > 0:
			if b & 1:
				ans = ans * a % self.p
			a = a * a % self.p
			b >>= 1
		return ans

	def fact_inv(self, a):
		return self.power_func(a, self.p - 2) % self.p
n = int(input())
fact = Facts(max_num=200000)
edges = defaultdict(lambda : [])
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edges[a].append(b)
	edges[b].append(a)
size = [1 for _ in range(n + 1)]

def dfs1(num, par=-1):
	res = 1
	for node in edges[num]:
		if node == par:
			continue
		else:
			res += dfs1(node, num)
	res %= MOD
	size[num] = res
	return res
dfs1(1)
dp = [0 for _ in range(n + 1)]

def dfs2(n, par=-1):
	res = fact.fact[size[n] - 1]
	for node in edges[n]:
		if node == par:
			continue
		else:
			res *= dfs2(node, n) * fact.fact_inv(fact.fact[size[node]])
	res %= MOD
	dp[n] = res
	return res
dfs2(1)
ans = [0 for _ in range(n + 1)]
inv_1 = fact.fact_inv(fact.fact[n - 1])

def dfs3(num, par=-1):
	if par != -1:
		res = dp[num] * fact.fact_inv(fact.fact[size[num] - 1]) * fact.fact[n - 1] * ans[par] * inv_1 * fact.fact[n - size[num] - 1] * fact.fact[size[num]] * fact.fact_inv(dp[num]) * fact.fact_inv(fact.fact[n - size[num]]) % MOD
		ans[num] = res
	else:
		ans[num] = dp[num]
	for node in edges[num]:
		if node == par:
			continue
		dfs3(node, num)
dfs3(1)
print('\n'.join(list(map(str, ans[1:]))))


import sys
input = sys.stdin.readline
from collections import deque
mod = 10 ** 9 + 7
N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
	(x, y) = map(int, input().split())
	X[x - 1].append(y - 1)
	X[y - 1].append(x - 1)
P = [-1] * N
Q = deque([0])
R = []
while Q:
	i = deque.popleft(Q)
	R.append(i)
	for a in X[i]:
		if a != P[i]:
			P[a] = i
			X[a].remove(i)
			deque.append(Q, a)
unit = 1
merge = lambda a, b: a * b % mod
adj_bu = lambda a, i: a * inv(SIZE[i]) % mod
adj_td = lambda a, i, p: a * inv(N - SIZE[i]) % mod
adj_butd = lambda a, i: a * inv(N) % mod
nn = 200200
mod = 10 ** 9 + 7
fa = [1] * (nn + 1)
fainv = [1] * (nn + 1)
for i in range(nn):
	fa[i + 1] = fa[i] * (i + 1) % mod
fainv[-1] = pow(fa[-1], mod - 2, mod)
for i in range(nn)[::-1]:
	fainv[i] = fainv[i + 1] * (i + 1) % mod
inv = lambda i: fainv[i] * fa[i - 1] % mod
SIZE = [1] * N
for i in R[1:][::-1]:
	SIZE[P[i]] += SIZE[i]
ME = [unit] * N
XX = [0] * N
TD = [unit] * N
for i in R[1:][::-1]:
	XX[i] = adj_bu(ME[i], i)
	p = P[i]
	ME[p] = merge(ME[p], XX[i])
XX[R[0]] = adj_bu(ME[R[0]], R[0])
for i in R:
	ac = TD[i]
	for j in X[i]:
		TD[j] = ac
		ac = merge(ac, XX[j])
	ac = unit
	for j in X[i][::-1]:
		TD[j] = adj_td(merge(TD[j], ac), j, i)
		ac = merge(ac, XX[j])
		XX[j] = adj_butd(merge(ME[j], TD[j]), j)
XX = [x * fa[N] % mod for x in XX]
print(*XX, sep='\n')


import sys
input = sys.stdin.readline
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def mul(a, b):
	return a % mod * (b % mod) % mod

def div(a, b):
	return mul(a, modinv(b))

def modinv(a):
	(b, u, v) = (mod, 1, 0)
	while b:
		t = a // b
		(a, u) = (a - t * b, u - t * v)
		(a, b, u, v) = (b, a, v, u)
	u %= mod
	return u

def cmb(n, r):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
NNN = 2 * 10 ** 5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, NNN + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
(N,) = map(int, input().split())
d = [list() for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	d[a].append(b)
	d[b].append(a)
vs = set([1])
stack = [1]
vs_bfs = list()
parents = [0] * (N + 1)
while stack:
	v = stack.pop()
	vs_bfs.append(v)
	for u in d[v]:
		if u in vs:
			continue
		parents[u] = v
		vs.add(u)
		stack.append(u)
dp1 = [0 for _ in range(N + 1)]
sss = [0 for _ in range(N + 1)]
for v in vs_bfs[::-1]:
	t = 1
	ts = []
	for u in d[v]:
		if u == parents[v]:
			continue
		t = mul(dp1[u], t)
		ts.append(sss[u])
	st = sum(ts)
	sss[v] = st + 1
	for tt in ts:
		t = mul(cmb(st, tt), t)
		st -= tt
	dp1[v] = t
for v in vs_bfs:
	if v == 1:
		continue
	p = parents[v]
	dp1[v] = mul(mul(dp1[p], sss[v]), inverse[N - sss[v]])
for x in dp1[1:]:
	print(x)


MOD = 10 ** 9 + 7
fac = [1] * (2 * 10 ** 5 + 10)
for i in range(len(fac) - 1):
	fac[i + 1] = fac[i] * (i + 1) % MOD

def euler_tour(G, root=0):
	n = len(G)
	euler = []
	dq = [root]
	visited = [0] * n
	while dq:
		u = dq.pop()
		euler += [u]
		if visited[u]:
			continue
		dq += [u]
		for v in G[u]:
			if visited[v]:
				continue
			else:
				dq += [v]
		visited[u] = 1
	return euler
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
e = euler_tour(g)
pr = [-1] * n
d = [0] * n
for (i, x) in enumerate(e):
	if pr[x] == -1:
		pr[x] = i
	else:
		d[x] = (i - pr[x]) // 2
s = [0]
p = [0] * n
v = [0] * n
for node in e:
	if v[node]:
		for t in g[node]:
			if d[t] <= d[node]:
				p[node] = p[node] * pow(fac[d[t] + 1], MOD - 2, MOD) * p[t] % MOD
	else:
		v[node] = 1
		p[node] = fac[d[node]]
s = [0]
ans = [0] * n
ans[0] = p[0]
while s:
	p = s.pop()
	for node in g[p]:
		if not ans[node]:
			ans[node] = ans[p] * (d[node] + 1) * pow(n - d[node] - 1, MOD - 2, MOD) % MOD
			s.append(node)
for row in ans:
	print(row)


import sys
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
N = ir()
graph = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = lr()
	graph[a].append(b)
	graph[b].append(a)
MOD = 10 ** 9 + 7
fact = [1] * (N + 10)
for n in range(1, N + 10):
	fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
	fact_inv[n - 1] = fact_inv[n] * n % MOD
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	cur = stack.pop()
	order.append(cur)
	for next in graph[cur]:
		if next == parent[cur]:
			continue
		parent[next] = cur
		stack.append(next)
size_down = [0] * (N + 1)
dp_down = [1] * (N + 1)
for v in order[::-1]:
	dp_down[v] *= fact[size_down[v]]
	dp_down[v] %= MOD
	p = parent[v]
	s = size_down[v] + 1
	size_down[p] += s
	dp_down[p] *= fact_inv[s] * dp_down[v]
	dp_down[p] %= MOD
size_up = [N - x - 1 for x in size_down]
dp_up = [1] * (N + 1)
for v in order[1:]:
	p = parent[v]
	x = dp_down[p]
	x *= dp_up[p]
	x *= fact_inv[size_down[p]]
	x *= fact[size_down[v] + 1]
	x *= pow(dp_down[v], MOD - 2, MOD)
	x %= MOD
	x *= fact[size_up[v] - 1]
	x *= fact_inv[size_up[p]]
	dp_up[v] = x % MOD
size_up[1] = 0
dp_up[1] = 1
for (xd, xu, sd, su) in zip(dp_down[1:], dp_up[1:], size_down[1:], size_up[1:]):
	answer = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % MOD
	print(answer % MOD)


N = int(input())
AB = [list(map(int, input().split())) for i in range(N - 1)]
c = [[] for i in range(N)]
for (a, b) in AB:
	c[a - 1].append(b - 1)
	c[b - 1].append(a - 1)
v = [1] + [0] * (N - 1)
x = [0]
s = []
parent = [-1] * N
child = [[] for i in range(N)]
while x:
	p = x.pop()
	s.append(p)
	for n in c[p]:
		if v[n] == 0:
			v[n] = 1
			x.append(n)
			parent[n] = p
			child[p].append(n)
m = 10 ** 9 + 7
fac = [1] * (N + 10)
inv = [1] * (N + 10)
ifac = [1] * (N + 10)
for n in range(2, N + 10):
	fac[n] = fac[n - 1] * n % m
	inv[n] = m - inv[m % n] * (m // n) % m
	ifac[n] = ifac[n - 1] * inv[n] % m
size = [1] * N + [0]
dp = [1] * N + [0]
for n in s[::-1]:
	p = parent[n]
	size[p] += size[n]
	dp[n] = dp[n] * fac[size[n] - 1] % m
	dp[p] = dp[p] * ifac[size[n]] * dp[n] % m
size2 = [N - v + 1 for v in size]
dp2 = [1] * N
for n in s[1:]:
	p = parent[n]
	dp2[n] = dp[p] * ifac[size[p] - 1] * dp2[p] * ifac[size2[p] - 1] * pow(dp[n], m - 2, m) * fac[size[n]] * fac[size2[n] - 2] % m
for i in range(N):
	print(dp[i] * dp2[i] * fac[size[i] + size2[i] - 2] * ifac[size[i] - 1] * ifac[size2[i] - 1] % m)


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def ZIP(n):
	return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
lim = N + 10
fact = [1] * (lim + 1)
fact_inv = [1] * (lim + 1)
for n in range(1, lim + 1):
	fact[n] = fact[n - 1] * n % mod
fact_inv[lim] = pow(fact[lim], mod - 2, mod)
for n in range(lim, 0, -1):
	fact_inv[n - 1] = n * fact_inv[n] % mod
tree = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = MAP()
	tree[a].append(b)
	tree[b].append(a)
order = []
parent = [0] * (N + 1)
stack = [1]
while stack:
	n = stack.pop()
	order.append(n)
	for node in tree[n]:
		if node == parent[n]:
			continue
		stack.append(node)
		parent[node] = n
size = [1] * (N + 1)
for v in order[::-1]:
	size[parent[v]] += size[v]
dpLeaf = [1] * (N + 1)
for v in order[::-1]:
	pr = parent[v]
	dpLeaf[v] = dpLeaf[v] * fact[size[v] - 1] % mod
	dpLeaf[pr] = dpLeaf[pr] * dpLeaf[v] * fact_inv[size[v]] % mod
ans = [0] * (N + 1)
ans[1] = dpLeaf[1]
for v in order[1:]:
	pr = parent[v]
	ans[v] = ans[pr] * pow(N - size[v], mod - 2, mod) * size[v] % mod
print(*ans[1:], sep='\n')


import sys
from functools import reduce
MAX_INT = 2 ** 62 - 1
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
MOD = 10 ** 9 + 7

def mul_mod(*args, mod=MOD):
	return reduce(lambda a, b: a * b % mod, args)

def solve(g, f, fi, m):
	mul = mul_mod
	stack = [(0, 1)]
	pre_order = []
	n = len(g) - 1
	while stack:
		(pre, cur) = stack.pop()
		pre_order.append((pre, cur))
		for nxt in g[cur]:
			if nxt == pre:
				continue
			stack.append((cur, nxt))
	size = [1] * (n + 1)
	dp = [1] * (n + 1)
	for (pre, cur) in reversed(pre_order):
		dp[cur] = mul(dp[cur], f[size[cur] - 1])
		dp[pre] = mul(dp[pre], dp[cur], fi[size[cur]])
		size[pre] += size[cur]
	ans = [1] * (n + 1)
	ans[1] = dp[1]
	for (pre, cur) in pre_order[1:]:
		i = size[cur]
		temp = mul(ans[pre], f[n - i - 1], fi[n - 1], f[i], pow(dp[cur], m - 2, m))
		ans[cur] = mul(f[n - 1], temp, fi[n - i], dp[cur], fi[i - 1])
	print(*ans[1:], sep='\n')

def main():
	mul = mul_mod
	mod = MOD
	n = int(input())
	g = [[] for _ in range(n + 1)]
	fact = [1] * (n + 1)
	fact_inv = [0] * (n + 1)
	for i in range(1, n + 1):
		fact[i] = mul(fact[i - 1], i)
	fact_inv[-1] = pow(fact[-1], mod - 2, mod)
	for i in range(n)[::-1]:
		fact_inv[i] = mul(fact_inv[i + 1], i + 1)
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		g[a].append(b)
		g[b].append(a)
	solve(g, fact, fact_inv, mod)

def __starting_point():
	main()
__starting_point()


import sys

def solve():
	input = lambda : sys.stdin.readline().rstrip()
	sys.setrecursionlimit(10 ** 7)
	mod = 10 ** 9 + 7

	def comb(n, r):
		if r > n:
			return 0
		return fac[n] * inv[r] * inv[n - r] % mod

	def dfs(v, Pa=-1):
		for u in to[v]:
			if u == Pa:
				continue
			dfs(u, v)
			size[v] += size[u]
			dp[v] *= dp[u] % mod
			dp[v] *= inv[size[u]] % mod
		dp[v] *= fac[size[v]] % mod
		size[v] += 1

	def bfs(v, Pa=-1, P_val=1, P_sz=0):
		ans[v] = P_val * dp[v] * comb(n - 1, P_sz) % mod
		for u in to[v]:
			if u == Pa:
				continue
			val = ans[v] * INV(dp[u] * comb(n - 1, size[u])) % mod
			bfs(u, v, val, n - size[u])
	n = int(input())
	to = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = map(lambda x: int(x) - 1, input().split())
		to[a].append(b)
		to[b].append(a)
	fac = [1] * (n + 2)
	inv = [1] * (n + 2)
	for i in range(2, n + 1):
		fac[i] = fac[i - 1] * i % mod
	INV = lambda x: pow(x, mod - 2, mod)
	inv[n] = INV(fac[n])
	for i in range(n - 1, 1, -1):
		inv[i] = inv[i + 1] * (i + 1) % mod
	dp = [1] * n
	size = [0] * n
	ans = [0] * n
	dfs(0)
	bfs(0)
	print(*ans, sep='\n')
solve()


def main():
	import sys
	from collections import deque
	input = sys.stdin.readline
	mod = 1000000007
	nmax = 2 * 10 ** 5 + 10
	fac = [0] * nmax
	finv = [0] * nmax
	inv = [0] * nmax
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, nmax):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod

	def comb(n, r):
		if n < r:
			return 0
		else:
			return fac[n] * (finv[r] * finv[n - r] % mod) % mod
	N = int(input())
	adj = [[] for _ in range(N + 1)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		adj[a].append(b)
		adj[b].append(a)
	que = deque()
	que.append(1)
	seen = [-1] * (N + 1)
	seen[1] = 0
	par = [0] * (N + 1)
	child = [[] for _ in range(N + 1)]
	seq = []
	while que:
		v = que.popleft()
		seq.append(v)
		for u in adj[v]:
			if seen[u] == -1:
				seen[u] = seen[v] + 1
				par[u] = v
				child[v].append(u)
				que.append(u)
	seq.reverse()
	dp = [1] * (N + 1)
	size = [1] * (N + 1)
	for v in seq:
		for u in child[v]:
			size[v] += size[u]
		L = size[v] - 1
		for u in child[v]:
			dp[v] = dp[v] * (dp[u] * comb(L, size[u])) % mod % mod
			L -= size[u]
	seq.reverse()
	dp2 = [0] * (N + 1)
	for v in seq:
		if v == 1:
			dp2[1] = dp[1]
			continue
		p = par[v]
		dp2[v] = dp[v]
		PP = dp2[p] * pow(dp[v] * comb(N - 1, size[v]) % mod, mod - 2, mod) % mod
		dp2[v] = dp2[v] * PP * comb(N - 1, size[v] - 1) % mod
	for v in range(1, N + 1):
		print(dp2[v])
main()


def main():
	from sys import stdin
	input = stdin.readline
	n = int(input())
	ab = [list(map(int, input().split())) for _ in [0] * (n - 1)]
	g = [set() for _ in [0] * n]
	for (a, b) in ab:
		g[a - 1].add(b - 1)
		g[b - 1].add(a - 1)
	mod = 10 ** 9 + 7
	fact = [1, 1]
	inv = [pow(i, mod - 2, mod) for i in range(n + 1)]
	for i in range(2, n + 1):
		fact.append(fact[-1] * i % mod)

	class rerooting:

		def __init__(self, tree, ini):

			def merge(a, b):
				return a * b % mod

			def adj_bu(a, i):
				return a * inv[size[i]] % mod

			def adj_td(a, i, p):
				return a * inv[n - size[i]] % mod

			def adj_fin(a, i):
				return a * fact[n - 1] % mod
			T = g
			P = [-1] * n
			q = [0]
			order = []
			while q:
				i = q.pop()
				order.append(i)
				for a in T[i]:
					if a != P[i]:
						P[a] = i
						T[a].remove(i)
						q.append(a)
			T = [list(i) for i in T]
			size = [1] * n
			for i in order[1:][::-1]:
				size[P[i]] += size[i]
			ME = [ini] * n
			DP = [0] * n
			for i in order[1:][::-1]:
				DP[i] = adj_bu(ME[i], i)
				p = P[i]
				ME[p] = merge(ME[p], DP[i])
			DP[order[0]] = adj_fin(ME[order[0]], order[0])
			TD = [ini] * n
			for i in order:
				ac = TD[i]
				for j in T[i]:
					TD[j] = ac
					ac = merge(ac, DP[j])
				ac = ini
				for j in T[i][::-1]:
					TD[j] = adj_td(merge(TD[j], ac), j, i)
					ac = merge(ac, DP[j])
					DP[j] = adj_fin(merge(ME[j], TD[j]), j)
			for i in DP:
				print(i)
	rerooting(g, 1)
main()


import sys
input = sys.stdin.readline
from collections import deque
mod = 10 ** 9 + 7
rng = 200100
fctr = [1]
finv = [1]
for i in range(1, rng):
	fctr.append(fctr[-1] * i % mod)
n = int(input())
ab = [list(map(int, input().split())) for i in range(n - 1)]
graph = [[] for i in range(n + 1)]
deg = [0] * (n + 1)
for (a, b) in ab:
	graph[a].append(b)
	graph[b].append(a)
	deg[a] += 1
	deg[b] += 1
deg[1] += 1
stack = [1]
cnt = [0] * (n + 1)
for i in range(2, n + 1):
	if deg[i] == 1:
		stack.append(i)
		cnt[i] = 1
dp = [[] for i in range(n + 1)]
while stack:
	x = stack.pop()
	if dp[x]:
		cnt[x] = sum(dp[x]) + 1
	for y in graph[x]:
		if deg[y] > 1:
			dp[y].append(cnt[x])
			deg[y] -= 1
			if deg[y] == 1:
				stack.append(y)

def euler_tour(G, root=1):
	n = len(G)
	euler = []
	dq = deque([root])
	dq2 = deque()
	visited = [0] * (n + 1)
	while dq:
		u = dq.pop()
		euler += [u]
		if visited[u]:
			continue
		for v in G[u]:
			if visited[v]:
				dq += [v]
			else:
				dq2 += [v]
		dq.extend(dq2)
		dq2 = deque()
		visited[u] = 1
	return euler
order = euler_tour(graph)
ans1 = fctr[n]
for i in range(1, n + 1):
	ans1 = ans1 * pow(cnt[i], mod - 2, mod) % mod
ans = [0] * (n + 1)
ans[1] = ans1
for i in range(1, len(order)):
	prv = order[i - 1]
	now = order[i]
	no = cnt[now]
	cnt[prv] -= cnt[now]
	cnt[now] += cnt[prv]
	pr = cnt[prv]
	if ans[now]:
		continue
	ans[now] = ans[prv] * pow(pr, mod - 2, mod) * no % mod
ans = ans[1:]
print(*ans, sep='\n')


import sys, os, io
input = sys.stdin.readline
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N - 1):
	(a, b) = list(map(int, input().split()))
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
mod = 10 ** 9 + 7

def fact(N):
	ans = [1] * (N + 1)
	for i in range(1, N + 1):
		ans[i] = ans[i - 1] * i % mod
	return ans

def combs_mod(n, k):
	inv = [1] * (k + 1)
	for i in range(1, k + 1):
		inv[i] = pow(i, mod - 2, mod)
	ans = [1] * (k + 1)
	for i in range(1, k + 1):
		ans[i] = ans[i - 1] * (n + 1 - i) * inv[i] % mod
	return ans

def dfs(start):
	stack = [start]
	parent = [N] * N
	parent[start] = -1
	fac = fact(N)
	while stack:
		v = stack[-1]
		marker = 0
		for u in edge[v]:
			if u == parent[v]:
				continue
			if parent[u] == N:
				marker = 1
				parent[u] = v
				stack.append(u)
			else:
				part_num[v] += part_num[u]
				ans[v] *= pow(fac[part_num[u]], mod - 2, mod) * ans[u] % mod
				ans[v] %= mod
		if marker == 0:
			stack.pop()
			ans[v] *= fac[part_num[v] - 1]
			ans[v] %= mod
	return

def dfs2(start):
	stack = [start]
	parent = [N] * N
	parent[start] = -1
	p_value = [0] * N
	combs = combs_mod(N - 1, N - 1)
	while stack:
		v = stack.pop()
		for (i, u) in enumerate(edge[v]):
			if u == parent[v]:
				continue
			parent[u] = v
			p_value[u] = ans[v] * pow(ans[u] * combs[part_num[u]], mod - 2, mod) % mod
			ans[u] *= combs[part_num[u] - 1] * p_value[u]
			ans[u] %= mod
			stack.append(u)
	return
ans = [1] * N
part_num = [1] * N
dfs(0)
dfs2(0)
print(*ans, sep='\n')


from collections import defaultdict
from functools import lru_cache
import sys
input = sys.stdin.readline

class Reroot:

	def __init__(self, N, e, merge, f, g):
		self.G = defaultdict(list)
		self.parents = [-1] * (N + 1)
		self.dp = defaultdict(lambda : defaultdict(int))
		self.merge = merge
		self.f = f
		self.g = g
		self.e = e

	def add_edge(self, s, t):
		self.G[s].append(t)

	def build(self):
		self.dfs1(1)
		self.dfs2(1)
		return self.dp

	def dfs1(self, s):
		l = []
		q = [1]
		while q:
			s = q.pop()
			l.append(s)
			for t in self.G[s]:
				if t == self.parents[s]:
					continue
				self.parents[t] = s
				q.append(t)
		for s in l[::-1]:
			v = self.e
			for t in self.G[s]:
				if t == self.parents[s]:
					continue
				v = self.merge(v, self.f(self.dp[s][t], s, t))
			self.dp[self.parents[s]][s] = self.g(v, self.parents[s], s)

	def dfs2(self, s):
		q = [(s, self.e)]
		while q:
			(s, dp_p) = q.pop()
			par = self.parents[s]
			self.dp[s][par] = dp_p
			size = len(self.G[s])
			ac_l = [self.e] * (size + 1)
			ac_r = [self.e] * (size + 1)
			for (i, t) in enumerate(self.G[s]):
				ac_l[i + 1] = self.merge(ac_l[i], self.f(self.dp[s][t], s, t))
			for (i, t) in enumerate(self.G[s][::-1]):
				ac_r[size - i - 1] = self.merge(ac_r[size - i], self.f(self.dp[s][t], s, t))
			self.dp[-1][s] = self.g(ac_l[size], -1, s)
			for (i, t) in enumerate(self.G[s]):
				if t == par:
					continue
				q.append((t, self.g(self.merge(ac_l[i], ac_r[i + 1]), t, s)))

def solve():
	N = int(input())
	MOD = 10 ** 9 + 7
	n = N
	fac = [1] * (n + 1)
	rev = [1] * (n + 1)
	d = defaultdict(list)
	for i in range(1, n + 1):
		fac[i] = i * fac[i - 1] % MOD
		rev[i] = pow(fac[i], MOD - 2, MOD)
	merge1 = lambda x, y: x + y
	f1 = lambda x, par, s: x
	g1 = lambda x, par, s: x + 1
	e1 = 0
	tree1 = Reroot(N, e1, merge1, f1, g1)
	merge2 = lambda x, y: x * y % MOD
	f2 = lambda x, par, s: x * rev[tree1.dp[par][s]] % MOD
	g2 = lambda x, par, s: x * fac[tree1.dp[par][s] - 1] % MOD
	e2 = 1
	tree2 = Reroot(N, e2, merge2, f2, g2)
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		tree2.add_edge(a, b)
		tree2.add_edge(b, a)
		tree1.add_edge(a, b)
		tree1.add_edge(b, a)
	tree1.build()
	ans = tree2.build()
	for i in range(1, N + 1):
		print(ans[-1][i])
solve()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	G[a].append(b)
	G[b].append(a)
mod = 10 ** 9 + 7
fact = [1] * N
fact_inv = [1] * N
for i in range(1, N):
	fact[i] = i * fact[i - 1] % mod
inv = lambda x: pow(x, mod - 2, mod)
fact_inv[N - 1] = inv(fact[N - 1])
for i in range(1, N)[::-1]:
	fact_inv[i - 1] = i * fact_inv[i] % mod
stack = [0]
parent = [-1] * N
order = []
while stack:
	v = stack.pop()
	order.append(v)
	for c in G[v]:
		if c != parent[v]:
			stack.append(c)
			parent[c] = v
dp = [1] * N
size = [1] * N
for v in order[::-1]:
	dp[v] = dp[v] * fact[size[v] - 1] % mod
	p = parent[v]
	if p == -1:
		break
	size[p] += size[v]
	dp[p] = dp[p] * dp[v] * fact_inv[size[v]] % mod
ans = [0] * N
ans[0] = dp[0]
for v in order[1:]:
	p = parent[v]
	ans[v] = ans[p] * size[v] * inv(N - size[v]) % mod
print(*ans, sep='\n')


M = 10 ** 9 + 7
N = 10 ** 5 * 2
fac = [0] * (N + 1)
fac[0] = b = 1
for i in range(1, N + 1):
	fac[i] = b = b * i % M
inv = [0] * (N + 1)
inv[N] = b = pow(fac[N], M - 2, M)
for i in range(N, 0, -1):
	inv[i - 1] = b = b * i % M
(n, *t) = open(0).read().split()
n = int(n)
e = [[] for _ in range(n)]
for (a, b) in zip(*[map(int, t)] * 2):
	e[a - 1] += (b - 1,)
	e[b - 1] += (a - 1,)
o = []
s = [0]
f = [1] * n
while s:
	v = s.pop()
	f[v] = 0
	o += (v,)
	l = []
	for w in e[v]:
		if f[w]:
			l += (w,)
			s += (w,)
	e[v] = l
(sz1, sz2) = ([0] * n, [0] * n)
(dp1, dp2) = ([0] * n, [0] * n)
c = [[] for _ in range(n)]
for v in o[::-1]:
	s = 1
	(c1, c2) = ([1], [1])
	for w in e[v]:
		u = sz1[w]
		c1 += (c1[-1] * dp1[w] * inv[u] % M,)
		s += u
	for w in e[v][::-1]:
		c2 += (c2[-1] * dp1[w] * inv[sz1[w]] % M,)
	c[v] = (c1, c2[::-1])
	sz1[v] = s
	dp1[v] = c1[-1] * fac[s - 1] % M
sz2[0] = 1
dp2[0] = 1
for v in o:
	l = len(e[v])
	(c1, c2) = c[v]
	uv = sz2[v] - 1
	tv = dp2[v] * inv[uv]
	for (i, w) in enumerate(e[v]):
		tw = c1[i] * c2[i + 1] % M
		uw = uv + sz1[v] - sz1[w] - 1
		dp2[w] = tv * tw * fac[uw] % M
		sz2[w] = uw + 2
a = []
for (dp1, dp2, sz1, sz2) in zip(dp1, dp2, sz1, sz2):
	sz1 -= 1
	sz2 -= 1
	a += (str(dp1 * dp2 * inv[sz1] * inv[sz2] * fac[sz1 + sz2] % M),)
print('\n'.join(a))


import sys
sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7

def prepare(n):
	nonlocal MOD
	modFacts = [0] * (n + 1)
	modFacts[0] = 1
	for i in range(n):
		modFacts[i + 1] = modFacts[i] * (i + 1) % MOD
	invs = [1] * (n + 1)
	invs[n] = pow(modFacts[n], MOD - 2, MOD)
	for i in range(n, 1, -1):
		invs[i - 1] = invs[i] * i % MOD
	return (modFacts, invs)

def dfs(v):
	nonlocal MOD
	childs = 0
	var = 1
	for e in edge[v]:
		if path[e] == 0:
			path[e] = 1
			(nc, nvar) = dfs(e)
			childs += nc
			V[v][e] = (nc, nvar)
			var *= nvar
			var %= MOD
			var *= invs[nc]
			var %= MOD
	var *= modFacts[childs]
	var %= MOD
	return (childs + 1, var)

def dfs2(v):
	nonlocal MOD
	tNodes = 0
	tVar = 1
	for (n, var) in V[v].values():
		tNodes += n
		tVar *= var
		tVar %= MOD
		tVar *= invs[n]
		tVar %= MOD
	tVar *= modFacts[tNodes]
	tVar %= MOD
	dp[v] = tVar
	for e in edge[v]:
		if dp[e] == 0:
			(eNodes, eVar) = V[v][e]
			nVar = tVar * invs[tNodes] * modFacts[eNodes] * modFacts[tNodes - eNodes] % MOD
			nVar *= pow(eVar, MOD - 2, MOD)
			nVar %= MOD
			V[e][v] = (tNodes - eNodes + 1, nVar)
			dfs2(e)
N = int(input())
edge = [[] for _ in range(N)]
for s in sys.stdin.readlines():
	(a, b) = map(int, s.split())
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
(modFacts, invs) = prepare(N)
V = [{} for _ in range(N)]
path = [0] * N
dp = [0] * N
path[0] = 1
dfs(0)
dfs2(0)
print(*dp, sep='\n')


n = int(input())
graph = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
mod = 10 ** 9 + 7
factorial = [1] * (n + 1)
factorial_inv = [1] * (n + 1)
for i in range(1, n + 1):
	factorial[i] = factorial[i - 1] * i % mod
factorial_inv[n] = pow(factorial[n], mod - 2, mod)
for i in range(n, 0, -1):
	factorial_inv[i - 1] = factorial_inv[i] * i % mod
pa = [0] * (n + 1)
dp = [1] * (n + 1)
size = [1] * (n + 1)
checked = []
stack = [i]
while stack:
	a = stack.pop()
	checked.append(a)
	for j in graph[a]:
		if pa[a] == j:
			continue
		else:
			stack.append(j)
			pa[j] = a
for i in checked[::-1]:
	p = pa[i]
	s = size[i]
	dp[i] *= factorial[s - 1]
	dp[i] %= mod
	dp[p] *= dp[i] * factorial_inv[s]
	dp[p] %= mod
	size[p] += s
size_ = [n - i + 1 for i in size]
dp_ = [1] * (n + 1)
for i in checked[1:]:
	p = pa[i]
	dp_[i] *= dp[p]
	dp_[i] *= factorial_inv[size[p] - 1]
	dp_[i] *= pow(dp[i], mod - 2, mod)
	dp_[i] *= factorial[size[i]]
	dp_[i] *= dp_[p]
	dp_[i] *= factorial_inv[size_[p] - 1]
	dp_[i] *= factorial[size_[i] - 2]
	dp_[i] %= mod
for i in range(1, n + 1):
	ans = factorial[n - 1] * dp[i] * dp_[i] * factorial_inv[size[i] - 1] * factorial_inv[size_[i] - 1]
	ans %= mod
	print(ans)


import sys
sys.setrecursionlimit(1234567890)
from collections import deque
(n, *L) = map(int, open(0).read().split())
mod = 10 ** 9 + 7

def prepare(m, mod=10 ** 9 + 7):
	fac = [1] * (m + 1)
	inv = [1] * (m + 1)
	for i in range(1, m + 1):
		fac[i] = fac[i - 1] * i % mod
	inv[-1] = pow(fac[-1], mod - 2, mod)
	for i in range(m - 1, -1, -1):
		inv[i] = inv[i + 1] * (i + 1) % mod
	return (fac, inv)
(fac, inv) = prepare(n)
con = [[] for _ in range(n)]
for (s, t) in zip(*[iter(L)] * 2):
	con[s - 1] += (t - 1,)
	con[t - 1] += (s - 1,)
par = [-1] * n
q = deque([0])
odr = []
while q:
	cur = q.popleft()
	odr += (cur,)
	for nxt in con[cur]:
		if nxt != par[cur]:
			par[nxt] = cur
			q.append(nxt)
sz = [1] * (n + 1)
st = 1
for i in odr[::-1]:
	sz[par[i]] += sz[i]
	st *= pow(sz[i], mod - 2, mod)
	st %= mod
ans = [st * fac[n] % mod] + [0] * (n - 1)
for i in odr[1:]:
	ans[i] = ans[par[i]] * sz[i] % mod * pow(n - sz[i], mod - 2, mod) % mod
print(*ans)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

def main():
	n = int(input())

	def cmb(n, r, mod):
		if r < 0 or r > n:
			return 0
		r = min(r, n - r)
		return g1[n] * g2[r] * g2[n - r] % mod
	mod = 10 ** 9 + 7
	g1 = [1, 1]
	g2 = [1, 1]
	inverse = [0, 1]
	for i in range(2, n + 1):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	ki = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		ki[a].append(b)
		ki[b].append(a)
	memo = {}

	def dfs(p, v):
		if (p, v) in memo:
			return memo[p, v]
		(size, pat) = (0, 1)
		(tmps, tmpp) = (1, 1)
		deg = len(ki[v])
		for nv in ki[v]:
			if nv == p:
				continue
			(si, pi) = dfs(v, nv)
			size += si
			tmps *= g2[si]
			tmps %= mod
			tmpp *= pi
			tmpp %= mod
		pat = g1[size] * tmps * tmpp % mod
		memo[p, v] = (size + 1, pat)
		return (size + 1, pat)
	ans = [0] * n

	def bfs(p, v, res):
		if p != -1:
			memo[v, p] = res
		deg = len(ki[v])
		(tmps, tmpp) = (1, 1)
		for i in range(deg):
			(si, pi) = memo[v, ki[v][i]]
			tmps *= g2[si]
			tmpp *= pi
			tmps %= mod
			tmpp %= mod
		ans[v] = g1[n - 1] * tmps * tmpp
		ans[v] %= mod
		dpl = [1] * (deg + 1)
		dpr = [1] * (deg + 1)
		tmp = 1
		for i in range(deg):
			(si, pi) = memo[v, ki[v][i]]
			tmp *= pi * g2[si]
			tmp %= mod
			dpl[i + 1] = tmp
		tmp = 1
		for i in range(deg - 1, -1, -1):
			(si, pi) = memo[v, ki[v][i]]
			tmp *= pi * g2[si]
			tmp %= mod
			dpr[i] = tmp
		for i in range(deg):
			nv = ki[v][i]
			if p == nv:
				continue
			bfs(v, nv, (n - memo[v, nv][0], g1[n - 1 - memo[v, nv][0]] * dpl[i] * dpr[i + 1] % mod))
	dfs(-1, 0)
	bfs(-1, 0, 0)
	print(*ans, sep='\n')

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline
from collections import deque
nn = 200200
mod = 10 ** 9 + 7
fa = [1] * (nn + 1)
fainv = [1] * (nn + 1)
inv = [1] * (nn + 1)
for i in range(nn):
	fa[i + 1] = fa[i] * (i + 1) % mod
fainv[-1] = pow(fa[-1], mod - 2, mod)
for i in range(nn)[::-1]:
	fainv[i] = fainv[i + 1] * (i + 1) % mod
for i in range(1, nn)[::-1]:
	inv[i] = fainv[i] * fa[i - 1]
N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
	(x, y) = map(int, input().split())
	X[x - 1].append(y - 1)
	X[y - 1].append(x - 1)
P = [-1] * N
Q = deque([0])
R = []
while Q:
	i = deque.popleft(Q)
	R.append(i)
	for a in X[i]:
		if a != P[i]:
			P[a] = i
			X[a].remove(i)
			deque.append(Q, a)
unit = 1
f = lambda a, b: a * b % mod
g_bu = lambda a, i=-1: a * inv[SI[i]] % mod
g_td = lambda a, i=-1: a * inv[N - SI[i]] % mod
SI = [1] * N
for i in R[1:][::-1]:
	SI[P[i]] += SI[i]
BU = [unit] * N
TD = [unit] * N
for i in R[1:][::-1]:
	BU[i] = g_bu(BU[i], i)
	p = P[i]
	BU[p] = f(BU[p], BU[i])
BU[0] = g_bu(BU[0], 0)
AX = [1] * N
for i in R:
	ac = unit
	for j in X[i]:
		AX[j] = ac
		ac = f(ac, BU[j])
	ac = unit
	for j in X[i][::-1]:
		AX[j] = f(AX[j], ac)
		TD[j] = g_td(f(TD[i], AX[j]), j)
		ac = f(ac, BU[j])
print(*[BU[i] * SI[i] % mod * TD[i] % mod * fa[N - 1] % mod for i in range(N)], sep='\n')


n = int(input())
mod = 10 ** 9 + 7
max = 2 * 10 ** 5 + 10
(fac, finv, inv) = ([0] * max, [0] * max, [0] * max)

def comInit(max):
	fac[0] = fac[1] = 1
	finv[0] = finv[1] = 1
	inv[1] = 1
	for i in range(2, max):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod
comInit(max)

def com(n, k):
	if n < k:
		return 0
	if (n < 0) | (k < 0):
		return 0
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod
import sys
input = sys.stdin.readline
from collections import deque
graph = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)

def calc(a, b):
	(p_a, e_a) = a
	(p_b, e_b) = b
	e = e_a + e_b
	p = p_a * p_b * com(e, e_a) % mod
	return (p, e)

def calc1(c, p):
	(p_num, e_num) = (1, 0)
	for i in graph[c]:
		if i == p:
			continue
		(p_num, e_num) = calc((p_num, e_num), dp1[i])
	e_num += 1
	dp1[c] = (p_num, e_num)

def calc2(p):
	arr = [dp1[c] if c != parent[p] else dp2[p] for c in graph[p]]
	left = [(1, 0)]
	for i in arr[:-1]:
		left.append(calc(left[-1], i))
	right = [(1, 0)]
	for i in arr[:0:-1]:
		right.append(calc(right[-1], i))
	right = right[::-1]
	prod = []
	for (a, b) in zip(left, right):
		(p_tmp, e_tmp) = calc(a, b)
		prod.append((p_tmp, e_tmp))
	for (c, x) in zip(graph[p], prod):
		if c != parent[p]:
			(p_tmp, e_tmp) = x
			dp2[c] = (p_tmp, e_tmp + 1)
root = 1
order = []
parent = [0] * (n + 1)
stack = deque()
stack.append(root)
while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if y == parent[x]:
			continue
		stack.append(y)
		parent[y] = x
dp1 = [None] * (n + 1)
for i in order[::-1]:
	calc1(i, parent[i])
dp2 = [None] * (n + 1)
dp2[root] = (1, 0)
for i in order:
	calc2(i)
for i in range(1, n + 1):
	(p1, e1) = dp1[i]
	(p2, e2) = dp2[i]
	e1 -= 1
	ans = calc((p1, e1), (p2, e2))[0]
	print(ans)


import sys

def rerooting(n, edges, identity, merge, add_node):
	from functools import reduce
	G = [[] for _ in range(n)]
	for (a, b) in edges:
		G[a].append(b)
		G[b].append(a)
	order = []
	stack = [0]
	while stack:
		v = stack.pop()
		order.append(v)
		for u in G[v]:
			stack.append(u)
			G[u].remove(v)
	dp_down = [0] * n
	for v in order[:0:-1]:
		dp_down[v] = add_node(reduce(merge, (dp_down[u] for u in G[v]), identity), v)
	dp_up = [identity] * n
	for v in order:
		Gv = G[v]
		if len(Gv) == 0:
			continue
		cum = identity
		right = [identity]
		for u in Gv[:0:-1]:
			cum = merge(dp_down[u], cum)
			right.append(cum)
		right.reverse()
		cum = dp_up[v]
		for (u, cum_r) in zip(Gv, right):
			dp_up[u] = add_node(merge(cum, cum_r), v)
			cum = merge(cum, dp_down[u])
	results = [add_node(merge(reduce(merge, (dp_down[u] for u in Gv), identity), dp_up[v]), v) for (v, Gv) in enumerate(G)]
	return results

class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		f = 1
		self.fac = fac = [f]
		for i in range(1, n_max + 1):
			f = f * i % mod
			fac.append(f)
		f = pow(f, mod - 2, mod)
		self.facinv = facinv = [f]
		for i in range(n_max, 0, -1):
			f = f * i % mod
			facinv.append(f)
		facinv.reverse()

	def __call__(self, n, r):
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

def main():
	N = int(sys.stdin.buffer.readline())
	m = map(int, sys.stdin.buffer.read().split())
	AB = tuple(((a - 1, b - 1) for (a, b) in zip(m, m)))
	mod = 10 ** 9 + 7
	comb = Combination(202020)
	identity = (1, 0)
	(fac, facinv) = (comb.fac, comb.facinv)

	def merge(a, b):
		(a0, a1) = a
		(b0, b1) = b
		return (a0 * b0 * fac[a1 + b1] * facinv[a1] * facinv[b1] % mod, a1 + b1)

	def add_node(a, idx):
		(a0, a1) = a
		return (a0, a1 + 1)
	Ans = rerooting(N, AB, identity, merge, add_node)
	print('\n'.join((str(ans) for (ans, _) in Ans)))
main()


class Combination:

	def __init__(self, n, mod):
		self.mod = mod
		self.fac = [1] * (n + 1)
		for i in range(1, n + 1):
			self.fac[i] = self.fac[i - 1] * i % self.mod
		self.invfac = [1] * (n + 1)
		self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
		for i in range(n - 1, 0, -1):
			self.invfac[i] = self.invfac[i + 1] * (i + 1) % self.mod

	def combination(self, n, r):
		return self.fac[n] * self.invfac[r] % self.mod * self.invfac[n - r] % self.mod

	def factorial(self, i):
		return self.fac[i]

	def invfactorial(self, i):
		return self.invfac[i]

class Rerooting(Combination):

	def __init__(self, adjacent, n, mod):
		super(Rerooting, self).__init__(n, mod)
		self.n = n
		self.adj = adjacent
		self.order = []
		stack = [0]
		self.parent = [-1] * n
		while stack:
			node = stack.pop()
			self.order.append(node)
			for child in self.adj[node]:
				if self.parent[node] == child:
					continue
				stack.append(child)
				self.parent[child] = node

	def merge(self, parent, child):
		self.size[parent] += self.size[child]
		self.dp[parent] *= self.combination(self.size[parent] - 1, self.size[child])
		self.dp[parent] %= self.mod
		self.dp[parent] *= self.dp[child]
		self.dp[parent] %= self.mod
		return self.dp[parent]

	def remerge(self, parent, child):
		self.dp[child] = self.size[child] * self.dp[parent]
		self.dp[child] *= pow(self.n - self.size[child], self.mod - 2, self.mod)
		self.dp[child] %= self.mod
		return self.dp[child]

	def calc_subtree(self):
		self.dp = [1] * self.n
		self.size = [1] * self.n
		for node in self.order[::-1]:
			if self.parent[node] == -1:
				continue
			self.merge(self.parent[node], node)

	def root_subtree(self):
		for node in self.order[1:]:
			p = self.parent[node]
			self.remerge(p, node)
		return self.dp

def main():
	import sys
	input = lambda : sys.stdin.buffer.readline().rstrip()
	n = int(input())
	mod = 10 ** 9 + 7
	adj = [[] for i in range(n)]
	for i in range(n - 1):
		(a, b) = map(lambda x: int(x) - 1, input().split())
		adj[a].append(b)
		adj[b].append(a)
	r = Rerooting(adj, n, mod)
	r.calc_subtree()
	dp = r.root_subtree()
	for ans in dp:
		print(ans)
main()


import sys
sys.setrecursionlimit(10 ** 7)

def modinv(a, m=10 ** 9 + 7):
	if a == 0:
		return 1
	b = m
	(x, lastx) = (0, 1)
	(y, lasty) = (1, 0)
	while b != 0:
		q = a // b
		(a, b) = (b, a % b)
		(x, lastx) = (lastx - q * x, x)
		(y, lasty) = (lasty - q * y, y)
	return lastx % m

def cur(p):
	for x in neighbor[p]:
		if x == par[p]:
			continue
		par[x] = p
		descend[p] += cur(x)
	return descend[p]

def cur2(p):
	for x in neighbor[p]:
		if x == par[p]:
			continue
		ans[x] = ans[p] * descend[x] * modinv(n - descend[x]) % mod
		cur2(x)
mod = 10 ** 9 + 7
n = int(input())
neighbor = [[] for _ in range(n + 1)]
descend = [1] * (n + 1)
par = [0] * (n + 1)
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	neighbor[a].append(b)
	neighbor[b].append(a)
cur(1)
ans = [1] * (n + 1)
ans1 = 1
for i in range(1, n + 1):
	ans1 = ans1 * i * modinv(descend[i]) % mod
ans[1] = ans1
cur2(1)
for i in range(1, n + 1):
	print(ans[i])


import bisect, sys
import math
from collections import deque

def sRaw():
	return input().rstrip('\r')

def iRaw():
	return int(input())

def ssRaw():
	return input().split()

def isRaw():
	return list(map(int, ssRaw()))
INF = 1 << 29
DIV = 10 ** 9 + 7

def mod_inv_prime(a, mod=DIV):
	return pow(a, mod - 2, mod)

def mod_inv(a, b):
	r = a
	w = b
	u = 1
	v = 0
	while w != 0:
		t = r // w
		r -= t * w
		(r, w) = (w, r)
		u -= t * v
		(u, v) = (v, u)
	return (u % b + b) % b

def CONV_TBL(max, mod=DIV):
	(fac, finv, inv) = ([0] * max, [0] * max, [0] * max)
	fac[0] = fac[1] = 1
	finv[0] = finv[1] = 1
	inv[1] = 1
	for i in range(2, max):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod

	class CONV:

		def __init__(self):
			self.fac = fac
			self.finv = finv
			pass

		def ncr(self, n, k):
			if n < k:
				return 0
			if n < 0 or k < 0:
				return 0
			return fac[n] * (finv[k] * finv[n - k] % DIV) % DIV
	return CONV()
sys.setrecursionlimit(200005)

def main():
	N = iRaw()
	G = [[] for _ in range(N)]
	dp = [0] * N
	sizs = [0] * N
	CONV = CONV_TBL(N + 1)
	for _ in range(N - 1):
		(a, b) = isRaw()
		G[a - 1].append(b - 1)
		G[b - 1].append(a - 1)

	def dfs(cur, pre):
		val = 1
		siz = 0
		for v in G[cur]:
			if v == pre:
				continue
			dfs(v, cur)
			siz += sizs[v]
			val = val * dp[v] * CONV.ncr(siz, sizs[v]) % DIV
		dp[cur] = val
		sizs[cur] = siz + 1

	def reroot(cur, pre):
		for v in G[cur]:
			if v == pre:
				continue
			val = dp[cur] * sizs[v] % DIV
			res = sizs[0] - sizs[v]
			dp[v] = val * CONV.finv[res] * CONV.fac[res - 1] % DIV
			reroot(v, cur)
	dfs(0, -1)
	reroot(0, -1)
	return '\n'.join([str(d) for d in dp])
print(main())


import sys
sys.setrecursionlimit(505050)

class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		f = 1
		self.fac = fac = [f]
		for i in range(1, n_max + 1):
			f = f * i % mod
			fac.append(f)
		f = pow(f, mod - 2, mod)
		self.facinv = facinv = [f]
		for i in range(n_max, 0, -1):
			f = f * i % mod
			facinv.append(f)
		facinv.reverse()
N = int(input())
G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = list(map(int, input().split()))
	G[a].append(b)
	G[b].append(a)
Siz = [0] * (N + 1)
A = [0] * (N + 1)
mod = 10 ** 9 + 7
comb = Combination(202020)

def dfs1(v, p):
	siz = 1
	an_prod = 1
	an_numer = 0
	an_denom = 1
	for u in G[v]:
		if u != p:
			(s, a) = dfs1(u, v)
			siz += s
			an_prod = an_prod * a % mod
			an_numer += s
			an_denom = an_denom * comb.facinv[s] % mod
	an_numer = comb.fac[an_numer]
	an = an_numer * an_denom % mod * an_prod % mod
	Siz[v] = siz
	A[v] = an
	return (siz, an)
(_, ans) = dfs1(1, 0)
Ans = [0] * (N + 1)
Ans[1] = ans

def dfs2(v, p, an_p):
	siz_v = Siz[v]
	if v == 1:
		ans = A[v]
	else:
		ans = A[v] * comb.fac[N - 1] % mod * comb.facinv[siz_v - 1] % mod * an_p % mod * comb.facinv[N - siz_v] % mod
		Ans[v] = ans
	for u in G[v]:
		if p != u:
			siz_u = Siz[u]
			an = ans * comb.facinv[N - 1] % mod * comb.fac[N - 1 - siz_u] % mod * comb.fac[siz_u] % mod * pow(A[u], mod - 2, mod) % mod
			dfs2(u, v, an)
dfs2(1, 0, None)
print('\n'.join(map(str, Ans[1:])))


import sys
sys.setrecursionlimit(200010)
mod = 1000000007

def pow_mod(x, y):
	res = 1
	while y > 0:
		if y % 2:
			res *= x
			res %= mod
		x *= x
		x %= mod
		y //= 2
	return res

def inverse(x):
	return pow_mod(x, mod - 2)
N = int(input())
E = []
for i in range(N):
	E.append([])
for i in range(N - 1):
	(a, b) = list(map(int, input().split()))
	a -= 1
	b -= 1
	E[a].append(b)
	E[b].append(a)
kai = [1] * (N + 1)
fkai = [1] * (N + 1)
for i in range(N):
	kai[i + 1] = kai[i] * (i + 1) % mod
fkai[N] = inverse(kai[N])
for i in range(N - 1, 0, -1):
	fkai[i] = fkai[i + 1] * (i + 1) % mod
child = [0] * N
dp = [0] * N
ans = [0] * N

def dfs1(now, par):
	res = 1
	for to in E[now]:
		if to == par:
			continue
		res += dfs1(to, now)
	child[now] = res
	return res

def dfs2(now, par):
	res = kai[child[now] - 1]
	for to in E[now]:
		if to == par:
			continue
		res *= fkai[child[to]]
		res %= mod
		res *= dfs2(to, now)
		res %= mod
	dp[now] = res
	return res

def dfs3(now, par):
	ans[now] = dp[now]
	seki = 1
	for to in E[now]:
		if to == par:
			continue
		seki *= dp[to]
		seki %= mod
	for to in E[now]:
		if to == par:
			continue
		m_now = dp[now]
		m_to = dp[to]
		m_c_now = child[now]
		m_c_to = child[to]
		dp[now] *= kai[N - 1 - child[to]] * kai[child[to]] % mod * fkai[N - 1] % mod * inverse(dp[to]) % mod
		dp[now] %= mod
		dp[to] *= kai[N - 1] * dp[now] % mod * fkai[N - child[to]] % mod * fkai[child[to] - 1] % mod
		dp[to] %= mod
		child[now] -= child[to]
		child[to] = N
		dfs3(to, now)
		dp[now] = m_now
		dp[to] = m_to
		child[now] = m_c_now
		child[to] = m_c_to
dfs1(0, -1)
dfs2(0, -1)
dfs3(0, -1)
for i in range(N):
	print(ans[i])


import sys
sys.setrecursionlimit(10 ** 7)

class Tree:
	(C, RL) = ({}, {})
	(R, N, D, S, P, T) = (None, None, None, None, None, None)
	TL = None

	def __init__(s, num):
		s.N = num

	def set(s, a, b):
		if a in s.C:
			s.C[a].append(b)
		else:
			s.C[a] = [b]
		if b in s.C:
			s.C[b].append(a)
		else:
			s.C[b] = [a]

	def makeRank(s, root):
		s.R = [0] * s.N
		s.R[root] = 1
		s.RL[1] = [root]
		s.S = {}
		s.P = [-1] * s.N
		s.D = 1
		while s.RL[s.D] != []:
			s.D += 1
			s.RL[s.D] = []
			for i in s.RL[s.D - 1]:
				for j in s.C[i]:
					if s.R[j] == 0:
						s.R[j] = s.D
						s.RL[s.D].append(j)
						if i not in s.S:
							s.S[i] = [j]
						else:
							s.S[i].append(j)
						s.P[j] = i

	def bottomUpDP(s):
		for i in range(s.D - 2, 0, -1):
			T = s.RL[i]
			for j in T:
				if j not in s.S:
					continue
				for k in s.S[j]:
					s.dp_sub_exe(j, k)

	def topDownDP(s):
		for i in range(2, s.D):
			T = s.RL[i]
			for j in T:
				s.dp_sub_exe_inv(j, s.P[j])

	def allDP(s):
		s.dp_init()
		s.bottomUpDP()
		s.topDownDP()
		return s.DP

	def dp_init(s):
		s.DP = [1] * N
		s.sDP = [1] * N

	def dp_sub_exe(s, x, y):
		s.sDP[x] += s.sDP[y]
		s.DP[x] = s.DP[x] * s.DP[y] * com.com(s.sDP[x] - 1, s.sDP[y]) % MOD

	def dp_sub_exe_inv(s, x, y):
		t = com.com(s.sDP[y] - 1, s.sDP[x]) * s.DP[x] % MOD
		t = s.DP[y] * s.inv(t, MOD)
		k = s.sDP[y] - s.sDP[x]
		k = com.com(s.sDP[y] - 1, k) % MOD
		s.sDP[x] = s.sDP[y]
		s.DP[x] = s.DP[x] * t * k % MOD

	def inv(s, a, mod):
		return pow(a, mod - 2, mod)

class comb:
	F = [1, 1]
	Fi = [1, 1]
	I = [0, 1]

	def __init__(self, num, mod):
		self.MOD = mod
		for i in range(2, num + 1):
			self.F.append(self.F[-1] * i % mod)
			self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
			self.Fi.append(self.Fi[-1] * self.I[i] % mod)

	def com(self, n, k):
		if n < k:
			return 0
		if n < 0 or k < 0:
			return 0
		return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
MOD = 10 ** 9 + 7
com = comb(N, MOD)
T = Tree(N)
for (a, b) in ab:
	a -= 1
	b -= 1
	T.set(a, b)
T.makeRank(0)
DP = T.allDP()
for i in DP:
	print(i)


import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7

def cmb(n, r, mod=mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
NN = 4 * 10 ** 5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, NN + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
Child = [1] * N
Score = [1] * N

def dfs1(s):
	stack = [s]
	Ind = [0] * N
	while stack:
		p = stack[-1]
		if Ind[p] == len(graph[p]):
			stack.pop()
			par = -1
			if len(stack) > 0:
				par = stack[-1]
			P = []
			for ch in graph[p]:
				if ch == par:
					continue
				Child[p] += Child[ch]
				P.append([Score[ch], Child[ch]])
			tmp = Child[p] - 1
			for (s, c) in P:
				Score[p] = Score[p] * s * cmb(tmp, c) % mod
				tmp -= c
		elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]]:
			Ind[p] += 1
		else:
			stack.append(graph[p][Ind[p]])
			Ind[p] += 1
ans = [-1] * N

def dfs2(s):
	stack = [s]
	ans[s] = Score[s]
	Ind = [0] * N
	while stack:
		p = stack[-1]
		if Ind[p] == len(graph[p]):
			stack.pop()
			if len(stack) > 0:
				par = stack[-1]
				kiyo = Score[par] * cmb(Child[p] - 1, Child[par])
				Score[p] = Score[p] * pow(kiyo, mod - 2, mod) % mod
				Child[p] -= Child[par]
				Child[par] += Child[p]
				Score[par] = Score[par] * Score[p] * cmb(Child[par] - 1, Child[p]) % mod
		elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]]:
			Ind[p] += 1
		else:
			ch = graph[p][Ind[p]]
			kiyo = Score[ch] * cmb(Child[p] - 1, Child[ch])
			Score[p] = Score[p] * pow(kiyo, mod - 2, mod) % mod
			Child[p] -= Child[ch]
			Child[ch] += Child[p]
			Score[ch] = Score[ch] * Score[p] * cmb(Child[ch] - 1, Child[p]) % mod
			ans[ch] = Score[ch]
			stack.append(ch)
			Ind[p] += 1

def main():
	dfs1(0)
	dfs2(0)
	print(*ans, sep='\n')
main()


import sys
sys.setrecursionlimit(1 << 30)
mod = 10 ** 9 + 7

def inv(x):
	return pow(x, mod - 2, mod)

def dfs_size(x):
	sizex = 1
	for y in edges[x]:
		if y != parent[x]:
			parent[y] = x
			sizex += dfs_size(y)
	size[x] = sizex
	return sizex

def dfs_dp(x):
	dpx = 1
	for y in edges[x]:
		if y != parent[x]:
			dpx *= dfs_dp(y)
			dpx *= inv_fac[size[y]]
			dpx %= mod
	dpx *= fac[size[x] - 1]
	dpx %= mod
	dp[x] = dpx
	return dpx

def dfs_ans(x):
	ansx = 1
	if x != 1:
		for y in edges[x]:
			if y != parent[x]:
				ansx *= dp[y]
				ansx *= inv_fac[size[y]]
				ansx %= mod
			else:
				dpy = ans[y]
				dpy *= inv_fac[N - 1]
				dpy *= fac[size[x]]
				dpy *= fac[N - size[x] - 1]
				dpy *= inv(dp[x])
				dpy %= mod
				ansx *= dpy
				ansx *= inv_fac[N - size[x]]
				ansx %= mod
		ansx *= fac[N - 1]
		ansx %= mod
		ans[x] = ansx
	for y in edges[x]:
		if y != parent[x]:
			dfs_ans(y)
N = int(input())
edges = [[] for _ in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	edges[a].append(b)
	edges[b].append(a)
size = [0] * (N + 1)
parent = [0] * (N + 1)
dfs_size(1)
fac = [1]
for i in range(1, N + 1):
	fac.append(fac[-1] * i % mod)
inv_fac = [inv(fac[N])]
for i in range(1, N + 1)[::-1]:
	inv_fac.append(inv_fac[-1] * i % mod)
inv_fac = inv_fac[::-1]
dp = [0] * (N + 1)
dfs_dp(1)
ans = [0] * (N + 1)
ans[1] = dp[1]
dfs_ans(1)
for i in ans[1:]:
	print(i)


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10 ** 9 + 7
inf = float('inf')

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def dfs_1(s, p):
	par[s] = p
	for v in edges[s]:
		if v == p:
			continue
		size[s] += dfs_1(v, s)
	return size[s]

def dfs_2(s, p):
	dp1[s] = fact[size[s] - 1]
	for v in edges[s]:
		if v == p:
			continue
		dp1[s] = dp1[s] * dfs_2(v, s) % mod
		dp1[s] = dp1[s] * pow(fact[size[v]], mod - 2, mod) % mod
	return dp1[s]

def comb(n, r):
	return fact[n] * pow(fact[r], mod - 2, mod) * pow(fact[n - r], mod - 2, mod) % mod

def bfs(s):
	que = deque()
	que.append((s, -1))
	while que:
		(v, p) = que.popleft()
		if v == 0:
			dp2[v] = dp1[v]
		else:
			inv = dp2[p] * pow(dp1[v] * comb(n - 1, size[v]) % mod, mod - 2, mod) % mod
			dp2[v] = dp1[v] * inv * comb(n - 1, size[v] - 1) % mod
		for u in edges[v]:
			if u == p:
				continue
			que.append((u, v))
n = I()
fact = [1] * (n + 1)
par = [None] * n
for i in range(1, n + 1):
	fact[i] = i * fact[i - 1]
	fact[i] %= mod
edges = [[] for _ in range(n)]
size = [1] * n
dp1 = [0] * n
for _ in range(n - 1):
	(a, b) = LI()
	edges[a - 1].append(b - 1)
	edges[b - 1].append(a - 1)
dfs_1(0, -1)
dfs_2(0, -1)
dp2 = [0] * n
bfs(0)
for i in dp2:
	print(i)


import sys

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
N = 2 * 10 ** 5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
input = sys.stdin.readline
write = sys.stdout.write
N = int(input())
hen = {i: [] for i in range(1, N + 1)}
for i in range(0, N - 1):
	(a, b) = map(int, input().split())
	hen[a].append(b)
	hen[b].append(a)
parent = {i: -1 for i in range(1, N + 1)}
parent[1] = 0
q = []
q.append(1)
sub = []
while q != []:
	while q != []:
		x = q.pop()
		for p in hen[x]:
			if parent[p] == -1:
				parent[p] = x
				sub.append(p)
		if q == []:
			q = sub
			sub = []
			break
ans = {i: 1 for i in range(1, N + 1)}
subtreesize = {i: 1 for i in range(1, N + 1)}
flag = {i: 0 for i in range(0, N + 1)}
q = []
for i in range(1, N + 1):
	if i != 1 and len(hen[i]) == 1:
		q.append(i)
sub = []
while q != []:
	while q != []:
		x = q.pop()
		p = parent[x]
		if p != 1:
			ans[p] = ans[p] * ans[x] * g2[subtreesize[x]] % mod
			subtreesize[p] += subtreesize[x]
			flag[p] += 1
			if flag[p] == len(hen[p]) - 1:
				ans[p] = ans[p] * g1[subtreesize[p] - 1] % mod
				sub.append(p)
		else:
			subtreesize[1] += subtreesize[x]
			ans[1] = ans[1] * ans[x] * g2[subtreesize[x]] % mod
			flag[1] += 1
			if flag[1] == len(hen[1]):
				ans[1] = ans[1] * g1[subtreesize[1] - 1] % mod
		if q == []:
			q = sub
			sub = []
			break
q = [1]
flag2 = {i: 0 for i in range(1, N + 1)}
flag2[1] = 1
sub = []
while q != []:
	while q != []:
		x = q.pop()
		for p in hen[x]:
			if flag2[p] == 0:
				if len(hen[p]) != 1:
					ans[p] = ans[x] * pow(N - subtreesize[p], mod - 2, mod) * g1[subtreesize[p]] * g2[subtreesize[p] - 1] % mod
					flag2[p] = 1
					sub.append(p)
				else:
					ans[p] = ans[x] * pow(N - 1, mod - 2, mod) % mod
		if q == []:
			q = sub
			sub = []
			break
for i in range(1, N + 1):
	print(ans[i])


from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
sys.setrecursionlimit(2147483647)
INF = 10 ** 20

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def I():
	return int(sys.stdin.buffer.readline())

def LS():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]

def SRL(n):
	return [list(S()) for i in range(n)]

def MSRL(n):
	return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
n = I()
G = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = LI()
	G[a - 1] += [b - 1]
	G[b - 1] += [a - 1]
fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
	fac[j] = fac[j - 1] * j % mod
inv[n] = pow(fac[n], mod - 2, mod)
for j in range(n - 1, -1, -1):
	inv[j] = inv[j + 1] * (j + 1) % mod

def comb(n, r):
	if r > n or n < 0 or r < 0:
		return 0
	return fac[n] * inv[n - r] * inv[r] % mod
v_num = [-1] * n
par = [-1] * n

def f(u):
	ret = 1
	for v in G[u]:
		if v == par[u]:
			continue
		par[v] = u
		ret += f(v)
	v_num[u] = ret
	if u:
		return ret
f(0)
dp = [0] * n

def tree_dp(x):
	c = 1
	remain_v = v_num[x] - 1
	for y in G[x]:
		if y == par[x]:
			continue
		c = c * tree_dp(y) * comb(remain_v, v_num[y]) % mod
		remain_v -= v_num[y]
	dp[x] = c
	if x:
		return c
tree_dp(0)
ans = [0] * n

def dfs(d):
	e = 1
	inv_e = pow(comb(n - 1, v_num[d]) * dp[d], mod - 2, mod)
	ans[d] = dp[d] * ans[par[d]] * comb(n - 1, v_num[d] - 1) * inv_e % mod
q = deque([0])
ans[0] = dp[0]
while q:
	g = q.pop()
	for h in G[g]:
		if h == par[g]:
			continue
		dfs(h)
		q += [h]
for j in ans:
	print(j)


import sys
input = sys.stdin.readline
from collections import deque

class Factorial:

	def __init__(self, n, mod):
		self.f = [1]
		self.mod = mod
		for j in range(1, n + 1):
			self.f.append(self.f[-1] * j % mod)
		self.i = [pow(self.f[-1], mod - 2, mod)]
		for j in range(n, 0, -1):
			self.i.append(self.i[-1] * j % mod)
		self.i.reverse()

	def factorial(self, j):
		return self.f[j]

	def ifactorial(self, j):
		return self.i[j]

	def comb(self, n, k):
		return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0
MOD = 10 ** 9 + 7
N = int(input())
c = Factorial(N + 2, MOD)
G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	G[a].append(b)
	G[b].append(a)
edge_num = [len(G[i]) for i in range(N + 1)]
que = deque()
check = [0] * (N + 1)
order = []
o_append = order.append
q_pop = que.pop
q_append = que.append
q_append((1, 0))
check[1] = 1
while que:
	now = q_pop()
	o_append(now)
	for next_ in G[now[0]]:
		if check[next_] == 0:
			q_append((next_, now[0]))
			check[next_] = 1
size1 = [0] * (N + 1)
dp1 = [1] * (N + 1)
for (child, parent) in order[::-1]:
	dp1[child] *= c.factorial(size1[child])
	dp1[child] %= MOD
	s = size1[child] + 1
	size1[parent] += s
	dp1[parent] *= c.ifactorial(s) * dp1[child]
	dp1[parent] %= MOD
size2 = [N - 2 - x for x in size1]
dp2 = [1] * (N + 1)
for (child, parent) in order[1:]:
	x = dp1[parent]
	x *= dp2[parent]
	x *= c.ifactorial(size1[parent])
	x *= c.factorial(size1[child] + 1)
	x *= pow(dp1[child], MOD - 2, MOD)
	x *= c.factorial(size2[child])
	x *= c.ifactorial(size2[parent] + 1)
	dp2[child] = x % MOD
for (x1, x2, s1, s2) in zip(dp1[1:], dp2[1:], size1[1:], size2[1:]):
	s2 += 1
	x = x1 * x2 * c.factorial(s1 + s2) * c.ifactorial(s1) * c.ifactorial(s2) % MOD
	print(x)


import sys
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7
N = int(input())
fact = [1, 1]
fact_inv = [1, 1]
tmp_inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % mod)
	tmp_inv.append(-tmp_inv[mod % i] * (mod // i) % mod)
	fact_inv.append(fact_inv[-1] * tmp_inv[-1] % mod)

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return fact[n] * fact_inv[r] * fact_inv[n - r] % mod

def inv(a, mod):
	return pow(a, mod - 2, mod)
graph = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	graph[a].append(b)
	graph[b].append(a)
dp = [1] * (N + 0)
size = [0] * (N + 0)

def dfs(par, v):
	for u in graph[v]:
		if par == u:
			continue
		dfs(v, u)
		size[v] += size[u]
		dp[v] = dp[v] * dp[u] * fact_inv[size[u]] % mod
	dp[v] = dp[v] * fact[size[v]] % mod
	size[v] += 1
ans = [0] * (N + 0)

def reroot(par, val_par, size_par, v):
	ans[v] = val_par * dp[v] * cmb(N - 1, size_par, mod) % mod
	for u in graph[v]:
		if par == u:
			continue
		val = ans[v] * inv(dp[u] * cmb(N - 1, size[u], mod), mod) % mod
		reroot(v, val, N - size[u], u)
dfs(-1, 1)
reroot(-1, 1, 0, 1)
for i in range(N):
	print(ans[i])


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
mod = 10 ** 9 + 7
MAX = n
fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
	fact[i] = fact[i - 1] * i % mod
inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
	inv[i] = inv[mod % i] * (mod - mod // i) % mod
fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
	fact_inv[i] = fact_inv[i - 1] * inv[i] % mod
adj = [[] for _ in range(n + 1)]
for (a, b) in ab:
	adj[a].append(b)
	adj[b].append(a)
root = 1
stack = [root]
par = [0] * (n + 1)
order = []
while stack:
	u = stack.pop()
	order.append(u)
	for v in adj[u]:
		if v == par[u]:
			continue
		par[v] = u
		stack.append(v)
size_d = [0] * (n + 1)
dp_d = [1] * (n + 1)
for v in order[::-1]:
	dp_d[v] *= fact[size_d[v]]
	dp_d[v] %= mod
	s = size_d[v] + 1
	p = par[v]
	size_d[p] += s
	dp_d[p] *= fact_inv[s] * dp_d[v]
	dp_d[p] %= mod
size_u = [n - 2 - e for e in size_d]
dp_u = [1] * (n + 1)
for v in order[1:]:
	p = par[v]
	x = dp_d[p]
	x *= fact_inv[size_d[p]]
	x *= fact[size_d[v] + 1]
	x *= pow(dp_d[v], mod - 2, mod)
	x *= fact[size_u[v]]
	x *= fact_inv[size_u[p] + 1]
	x *= dp_u[p]
	dp_u[v] = x % mod
for (eu, su, ed, sd) in zip(dp_u[1:], size_u[1:], dp_d[1:], size_d[1:]):
	su += 1
	ans = eu * ed * fact[su + sd] * fact_inv[su] * fact_inv[sd] % mod
	print(ans)


import sys
from collections import defaultdict
MOD = 1000000007

class Combination(object):

	def __init__(self, N, mod=MOD):
		(fac, finv, inv) = ([0] * (N + 1), [0] * (N + 1), [0] * (N + 1))
		fac[:2] = (1, 1)
		finv[:2] = (1, 1)
		inv[1] = 1
		for i in range(2, N + 1):
			fac[i] = fac[i - 1] * i % mod
			inv[i] = -inv[mod % i] * (mod // i) % mod
			finv[i] = finv[i - 1] * inv[i] % mod
		self.N = N
		self.MOD = mod
		self.fac = fac
		self.finv = finv
		self.inv = inv

	def __call__(self, n, k):
		if n < k:
			return 0
		if n < 0 or k < 0:
			return 0
		b = self.finv[k] * self.finv[n - k] % self.MOD
		return self.fac[n] * b % self.MOD

def solve(N: int, a: 'List[int]', b: 'List[int]'):
	E = [[] for _ in range(N)]
	for (aa, bb) in zip(a, b):
		E[aa - 1].append(bb - 1)
		E[bb - 1].append(aa - 1)
	cmb = Combination(N)
	(front, back) = (-1, 1)
	downward = [0] * N
	parent = [-1] * N
	for _ in range(N - 1):
		front += 1
		v = downward[front]
		for u in E[v]:
			if u == parent[v]:
				continue
			parent[u] = v
			downward[back] = u
			back += 1
	dp = [1] * N
	size = [0] * N
	for v in reversed(downward):
		for u in E[v]:
			if u == parent[v]:
				continue
			size[v] += size[u] + 1
			dp[v] *= cmb.finv[size[u] + 1]
			dp[v] %= MOD
			dp[v] *= dp[u]
			dp[v] %= MOD
		dp[v] *= cmb.fac[size[v]]
		dp[v] %= MOD
	for v in downward:
		for u in E[v]:
			if u == parent[v]:
				continue
			dp[u] = dp[v]
			dp[u] *= (size[u] + 1) * cmb.inv[N - (size[u] + 1)]
			dp[u] %= MOD
	for v in dp:
		print(v)
	return

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	a = [int()] * (N - 1)
	b = [int()] * (N - 1)
	for i in range(N - 1):
		a[i] = int(next(tokens))
		b[i] = int(next(tokens))
	solve(N, a, b)
main()


from functools import *
from itertools import *
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
M = 10 ** 9 + 7
N = int(input())

@lru_cache(maxsize=None)
def mod_inv(x):
	return 1 if x == 1 else M // x * -mod_inv(M % x) % M
Weight = [0] * (N + 1)
Size = [0] * (N + 1)

def calc_subtree(v):
	(W, S) = (1, 1)
	for child in Edge[v]:
		Edge[child].remove(v)
		calc_subtree(child)
		W = W * Weight[child] % M
		S += Size[child]
	Weight[v] = W * S % M
	Size[v] = S
Ans = [0] * (N + 1)

def calc_ans(v, a):
	Ans[v] = a
	for child in Edge[v]:
		n = Size[child]
		calc_ans(child, a * n * mod_inv(N - n) % M)
Edge = [set() for i in range(N + 1)]
fact = N
for i in range(1, N):
	fact = fact * i % M
	(a, b) = map(int, input().split())
	Edge[a].add(b)
	Edge[b].add(a)
calc_subtree(1)
calc_ans(1, mod_inv(Weight[1]) * fact % M)
for a in islice(Ans, 1, None):
	print(a)


import sys
sys.setrecursionlimit(1000000)
mod = 7 + 10 ** 9
from collections import deque

def comb(n, r, fact, revfact, mod):
	return fact[n] * revfact[n - r] * revfact[r] % mod

def dfs1(i, pre, Edge, Dist, Son, fact, revfact):
	under = 0
	for ne in Edge[i]:
		if ne != pre:
			sonNum = dfs1(ne, i, Edge, Dist, Son, fact, revfact)
			under += sonNum
			Dist[i] *= comb(under, sonNum, fact, revfact, mod) * Dist[ne] % mod
			Dist[i] %= mod
	Son[i] = under
	return under + 1

def solve():
	input = sys.stdin.readline
	N = int(input())
	Edge = [[] for _ in range(N)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		Edge[a - 1].append(b - 1)
		Edge[b - 1].append(a - 1)
	fact = [1] * (N + 1)
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % mod
	revfact = [1] * (N + 1)
	revfact[N] = pow(fact[N], mod - 2, mod)
	for i in reversed(range(1, N)):
		revfact[i] = (i + 1) * revfact[i + 1] % mod
	Dist = [1] * N
	Son = [0] * N
	dfs1(0, 0, Edge, Dist, Son, fact, revfact)
	q = deque()
	for ne in Edge[0]:
		q.append((ne, 0))
	while q:
		(ne, pre) = q.pop()
		upper = Dist[pre] * pow(comb(N - 1, Son[ne] + 1, fact, revfact, mod), mod - 2, mod) % mod
		Dist[ne] = upper * comb(N - 1, N - 1 - Son[ne], fact, revfact, mod) % mod
		for nextEdge in Edge[ne]:
			if nextEdge != pre:
				q.append((nextEdge, ne))
	print('\n'.join(map(str, Dist)))
	return 0
solve()


import sys
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	graph[a].append(b)
	graph[b].append(a)
MAX = n + 5
fact = [1] * (MAX + 1)
finv = [1] * (MAX + 1)
iinv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
	fact[i] = fact[i - 1] * i % MOD
	iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * iinv[i] % MOD
ele_id = (1, 0)
dp = [[ele_id] * len(graph[i]) for i in range(n)]
ans = [ele_id] * n
add_func = lambda x: (x[0], x[1] + 1)

def merge_func(a, b):
	m = a[1] + b[1]
	dp_a = a[0] * finv[a[1]] % MOD
	dp_b = b[0] * finv[b[1]] % MOD
	c = dp_a * dp_b % MOD * fact[m] % MOD
	return (c, m)

def dfs1(v, v_p):
	dp_cum = ele_id
	for (i, v_next) in enumerate(graph[v]):
		if v_next == v_p:
			continue
		dp[v][i] = dfs1(v_next, v)
		dp_cum = merge_func(dp_cum, dp[v][i])
	return add_func(dp_cum)

def dfs2(v, v_p, dp_vp):
	for (i, v_next) in enumerate(graph[v]):
		if v_next == v_p:
			dp[v][i] = dp_vp
	dp_l = [ele_id] * (len(graph[v]) + 1)
	dp_r = [ele_id] * (len(graph[v]) + 1)
	for i in range(len(graph[v])):
		dp_l[i + 1] = merge_func(dp_l[i], dp[v][i])
	for i in reversed(range(len(graph[v]))):
		dp_r[i] = merge_func(dp_r[i + 1], dp[v][i])
	ans[v] = add_func(dp_l[-1])
	for (i, v_next) in enumerate(graph[v]):
		if v_next == v_p:
			continue
		dfs2(v_next, v, add_func(merge_func(dp_l[i], dp_r[i + 1])))
dfs1(0, -1)
dfs2(0, -1, ele_id)
for (ans_i, _) in ans:
	print(ans_i)


import sys
input = sys.stdin.readline
N = int(input())
E = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	E[a].append(b)
	E[b].append(a)
mod = 10 ** 9 + 7
FACT = [1]
for i in range(1, 2 * 10 ** 5 + 1):
	FACT.append(FACT[-1] * i % mod)
FACT_INV = [pow(FACT[-1], mod - 2, mod)]
for i in range(2 * 10 ** 5, 0, -1):
	FACT_INV.append(FACT_INV[-1] * i % mod)
FACT_INV.reverse()

def Combi(a, b):
	if 0 <= b <= a:
		return FACT[a] * FACT_INV[b] * FACT_INV[a - b] % mod
	else:
		return 0
Q = [1]
SORTED = [1]
USE = [0] * (N + 1)
USE[1] = 1
P = [-1] * (N + 1)
while Q:
	x = Q.pop()
	for to in E[x]:
		if USE[to] == 0:
			USE[to] = 1
			SORTED.append(to)
			Q.append(to)
			P[to] = x
FROM1 = [-1] * (N + 1)
FROM2 = [-1] * (N + 1)
for x in SORTED[::-1]:
	if len(E[x]) == 1 and x != 1:
		FROM1[x] = 1
		FROM2[x] = 1
	else:
		L = []
		SUML = 0
		A = 1
		for to in E[x]:
			if to == P[x]:
				continue
			L.append(FROM1[to])
			SUML += FROM1[to]
			A = A * FROM2[to] % mod
		FROM1[x] = SUML + 1
		S = SUML
		for l in L:
			A = A * Combi(S, l) % mod
			S -= l
		FROM2[x] = A
TO1 = [-1] * (N + 1)
TO2 = [-1] * (N + 1)
TO2[1] = 1
for x in SORTED:
	if x != 1 and len(E[x]) == 1:
		continue
	SS = 1
	L = []
	SUML = 0
	for to in E[x]:
		if to == P[x]:
			continue
		SS = SS * FROM2[to] % mod
		L.append(FROM1[to])
		SUML += FROM1[to]
	L.append(N - 1 - SUML)
	SUML += N - 1 - SUML
	A = 1
	S = SUML
	for l in L:
		A = A * Combi(S, l) % mod
		S -= l
	for to in E[x]:
		if to == P[x]:
			continue
		B = A * SS * pow(FROM2[to], mod - 2, mod) * TO2[x] % mod
		TO2[to] = B * pow(Combi(SUML, FROM1[to]), mod - 2, mod) % mod
for i in range(1, N + 1):
	ANS = TO2[i]
	L = []
	SUML = 0
	for to in E[i]:
		if to == P[i]:
			continue
		ANS = ANS * FROM2[to] % mod
		L.append(FROM1[to])
		SUML += FROM1[to]
	L.append(N - 1 - SUML)
	SUML += N - 1 - SUML
	S = SUML
	for l in L:
		ANS = ANS * Combi(S, l) % mod
		S -= l
	print(ANS % mod)


import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
e = dd(list)
mod = 10 ** 9 + 7
for _ in range(N - 1):
	(u, v) = map(int, input().split())
	e[u].append(v)
	e[v].append(u)

class Factorial:

	def __init__(self, n, mod):
		self.f = [1]
		for i in range(1, n + 1):
			self.f.append(self.f[-1] * i % mod)
		self.i = [pow(self.f[-1], mod - 2, mod)]
		for i in range(1, n + 1)[::-1]:
			self.i.append(self.i[-1] * i % mod)
		self.i.reverse()

	def factorial(self, i):
		return self.f[i]

	def ifactorial(self, i):
		return self.i[i]

	def combi(self, n, k):
		return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(N, mod)

class ReRooting:

	def ReRfunc(self, x):
		y = self.parent[x]
		return self.res[y] * self.size[x] % mod * pow(self.n - self.size[x], mod - 2, mod) % mod

	def __init__(self, n, e):
		self.n = n
		self.e = e
		self.vis = [0] * (n + 1)
		self.order = []
		self.parent = [-1] * (n + 1)
		self.ddp = [0] * (n + 1)
		self.udp = [0] * (n + 1)
		self._dfs()
		self.size = [1] * (n + 1)
		self.order.reverse()
		for x in self.order[:-1]:
			self.size[self.parent[x]] += self.size[x]
		self.res = [0] * (n + 1)
		self.res[1] = f.factorial(N)
		for x in range(1, N + 1):
			self.res[1] = self.res[1] * pow(self.size[x], mod - 2, mod) % mod
		self.order.reverse()
		for x in self.order[1:]:
			self.res[x] = self.ReRfunc(x)

	def _dfs(self):
		s = [1]
		while len(s):
			x = s.pop()
			self.vis[x] = 1
			self.order.append(x)
			for y in self.e[x]:
				if self.vis[y]:
					continue
				s.append(y)
				self.parent[y] = x

	def Size(self, x):
		return self.size[x]

	def Query(self, x):
		return self.res[x]
rer = ReRooting(N, e)
for x in range(1, N + 1):
	print(rer.Query(x) % mod)


from itertools import accumulate
MOD = 10 ** 9 + 7
table_len = 2 * 10 ** 5 + 10
fac = [1, 1]
for i in range(2, table_len):
	fac.append(fac[-1] * i % MOD)
finv = [0] * table_len
finv[-1] = pow(fac[-1], MOD - 2, MOD)
for i in range(table_len - 1, -1, -1):
	finv[i - 1] = finv[i] * i % MOD
N = int(input())
adj = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)
dfs_order = []
parent = [0] * (N + 1)
root = 1
stack = [root]
while stack:
	node = stack.pop()
	dfs_order.append(node)
	for child in adj[node]:
		if child != parent[node]:
			parent[child] = node
			stack.append(child)
dp1_size = [1] * (N + 1)
for node in reversed(dfs_order):
	for child in adj[node]:
		if child != parent[node]:
			dp1_size[node] += dp1_size[child]
dp2_size = [0] * (N + 1)
for node in dfs_order:
	around = [dp1_size[next_node] if next_node != parent[node] else dp2_size[node] for next_node in adj[node]]
	from_left = [0] + list(accumulate(around))[:-1]
	from_right = list(accumulate(reversed(around)))[-2::-1] + [0]
	without = [l + r for (l, r) in zip(from_left, from_right)]
	for (next_node, value) in zip(adj[node], without):
		if next_node != parent[node]:
			dp2_size[next_node] += value + 1
dp1 = [1] * (N + 1)
for node in reversed(dfs_order):
	s = 0
	for child in adj[node]:
		if child != parent[node]:
			s += dp1_size[child]
			dp1[node] *= dp1[child]
			dp1[node] %= MOD
			dp1[node] *= finv[dp1_size[child]]
			dp1[node] %= MOD
	dp1[node] *= fac[s]
	dp1[node] %= MOD

def func(t1, t2):
	(size1, value1) = t1
	(size2, value2) = t2
	size = size1 + size2
	comb = fac[size] * finv[size1] * finv[size2] % MOD
	value = comb * value1 * value2 % MOD
	return (size, value)
dp2 = [1] * (N + 1)
for node in dfs_order:
	around_size = [dp1_size[next_node] if next_node != parent[node] else dp2_size[node] for next_node in adj[node]]
	around = [dp1[next_node] if next_node != parent[node] else dp2[node] for next_node in adj[node]]
	from_left = [(0, 1)] + list(accumulate(zip(around_size, around), func))[:-1]
	from_right = list(accumulate(reversed(list(zip(around_size, around))), func))[-2::-1] + [(0, 1)]
	without = [func(l, r) for (l, r) in zip(from_left, from_right)]
	for (next_node, (_, value)) in zip(adj[node], without):
		if next_node != parent[node]:
			dp2[next_node] = value
for (size1, val1, size2, val2) in zip(dp1_size[1:], dp1[1:], dp2_size[1:], dp2[1:]):
	print(func((size1 - 1, val1), (size2, val2))[1])


import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline

def solve():
	N = int(input())
	AB = [tuple(map(int, input().split())) for i in range(N - 1)]
	es = [[] for i in range(N)]
	for (i, (a, b)) in enumerate(AB):
		(a, b) = (a - 1, b - 1)
		es[a].append((b, i))
		es[b].append((a, i))
	MOD = 10 ** 9 + 7
	size = [-1] * N

	def calc_size(v, p=-1):
		ret = 1
		for (to, _) in es[v]:
			if to == p:
				continue
			ret += calc_size(to, v)
		size[v] = ret
		return ret
	calc_size(0)
	MAXN = N + 5
	fac = [1, 1] + [0] * MAXN
	finv = [1, 1] + [0] * MAXN
	inv = [0, 1] + [0] * MAXN
	for i in range(2, MAXN + 2):
		fac[i] = fac[i - 1] * i % MOD
		inv[i] = -inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD
	dpdn = [0] * (N - 1)
	dn = set()

	def dfs(v, p=-1):
		ret = fac[size[v] - 1]
		for (to, i) in es[v]:
			if to == p:
				continue
			dn.add((v, to))
			dpdn[i] = dfs(to, v)
			ret *= finv[size[to]] * dpdn[i]
		ret %= MOD
		return ret
	dfs(0)
	dpup = [0] * (N - 1)
	from collections import deque
	q = deque([(0, -1)])
	while q:
		(v, p) = q.popleft()
		whole = 1
		for (to, i) in es[v]:
			if to != p:
				whole *= finv[size[to]] * dpdn[i]
			else:
				whole *= finv[N - size[v]] * dpup[i]
		whole %= MOD
		for (to, i) in es[v]:
			if to == p:
				continue
			dpup[i] = whole * fac[N - size[to] - 1] * fac[size[to]] * pow(dpdn[i], MOD - 2, MOD) % MOD
			q.append((to, v))
	ans = []
	for v in range(N):
		a = 1
		s = 0
		for (to, i) in es[v]:
			if (v, to) in dn:
				s += size[to]
				a *= finv[size[to]] * dpdn[i]
			else:
				s += N - size[v]
				a *= finv[N - size[v]] * dpup[i]
			a %= MOD
		a *= fac[s]
		ans.append(a % MOD)
	print(*ans, sep='\n')
solve()


MOD = 10 ** 9 + 7
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
fact = [1] * n
inverse = [1] * n
inv_fact = [1] * n
for i in range(2, n):
	fact[i] = fact[i - 1] * i % MOD
	inverse[i] = -inverse[MOD % i] * (MOD // i) % MOD
	inv_fact[i] = inv_fact[i - 1] * inverse[i] % MOD
stack = [0]
parent = [0] * n
route = []
while stack:
	vertex = stack.pop()
	route.append(vertex)
	for child in edge[vertex]:
		if parent[vertex] != child:
			parent[child] = vertex
			stack.append(child)
dp = [1] * n
size = [1] * n
for vertex in route[:0:-1]:
	pa = parent[vertex]
	sz = size[vertex]
	dp[vertex] = dp[vertex] * fact[sz - 1] % MOD
	dp[pa] = dp[pa] * dp[vertex] * inv_fact[sz] % MOD
	size[pa] += sz
dp[0] = dp[0] * fact[n - 1] % MOD
for vertex in route[1:]:
	pa = parent[vertex]
	sz = size[vertex]
	inv_dp = pow(dp[vertex], MOD - 2, MOD)
	dp[vertex] = dp[vertex] * dp[pa] * inv_dp * sz * inverse[n - sz] % MOD
for value in dp:
	print(value)


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
AB = [list(map(int, input().split())) for _ in [0] * (N - 1)]
mod = 10 ** 9 + 7
m = 10 ** 5 * 2 + 10
fac = [1] * m
ninv = [1] * m
finv = [1] * m
for i in range(2, m):
	fac[i] = fac[i - 1] * i % mod
	ninv[i] = -(mod // i) * ninv[mod % i] % mod
	finv[i] = finv[i - 1] * ninv[i] % mod
E = [[] for _ in [0] * N]
Ef = [[] for _ in [0] * N]
Eb = [[] for _ in [0] * N]
for (a, b) in AB:
	a -= 1
	b -= 1
	E[a].append(b)
	E[b].append(a)
done = [False] * N
done[0] = True
q = [0]
while q:
	j = q.pop()
	for k in E[j]:
		if done[k]:
			continue
		done[k] = True
		q.append(k)
		Ef[j].append(k)
		Eb[k].append(j)
Vf = [None] * N
Mf = [None] * N

def getf(i):
	if Mf[i] != None:
		return Mf[i]
	Mc = [getf(j) for j in Ef[i]]
	Vc = [Vf[j] for j in Ef[i]]
	Vf[i] = 1 + sum(Vc)
	Mf[i] = fac[Vf[i] - 1]
	for (mc, vc) in zip(Mc, Vc):
		Mf[i] *= mc * finv[vc] % mod
		Mf[i] %= mod
	return Mf[i]

def getp(i):
	if i == 0:
		return 0
	p = Eb[i][0]
	vp = Vf[p]
	vi = Vf[i]
	ret = ans[p]
	ret *= fac[vi] * fac[N - 1 - vi] % mod * finv[N - 1] % mod
	ret %= mod
	ret *= pow(Mf[i], mod - 2, mod)
	ret %= mod
	return ret
ans = [0] * N
ans[0] = getf(0)
q = Ef[0][:]
while q:
	i = q.pop()
	V = [N - Vf[i]]
	M = [getp(i)]
	for j in Ef[i]:
		q.append(j)
		V.append(Vf[j])
		M.append(Mf[j])
	tmp = fac[N - 1]
	for (mc, vc) in zip(M, V):
		tmp *= mc * finv[vc] % mod
		tmp %= mod
	ans[i] = tmp
for out in ans:
	print(out)


def main():
	mod = 10 ** 9 + 7
	fact = [1, 1]
	for i in range(2, 200000):
		fact.append(fact[-1] * i % mod)
	n = int(input())
	ab = [list(map(int, input().split())) for _ in [0] * (n - 1)]
	g = [[] for _ in [0] * n]
	[g[a - 1].append(b - 1) for (a, b) in ab]
	[g[b - 1].append(a - 1) for (a, b) in ab]
	g2 = [set(i) for i in g]
	child = [1] * n
	q = [-1, 0]
	while len(q) > 1:
		i = q[-1]
		if g2[i]:
			j = g2[i].pop()
			g2[j].remove(i)
			q.append(j)
		else:
			q.pop()
			if len(q) > 1:
				child[q[-1]] += child[i]
	rank = [(j, i) for (i, j) in enumerate(child)]
	rank = [j for (i, j) in sorted(rank)]
	dp = [1] * n
	for i in rank:
		c = child[i]
		ans = fact[c - 1]
		temp = 1
		for j in g[i]:
			if child[j] < c:
				ans = ans * dp[j] % mod
				temp = temp * fact[child[j]] % mod
		dp[i] = ans * pow(temp, mod - 2, mod) % mod
	dp2 = [0] * n
	dp2[0] = dp[0]
	g2 = [set(i) for i in g]
	q = [-1, 0]
	while len(q) > 1:
		i = q[-1]
		if g2[i]:
			j = g2[i].pop()
			c = child[j]
			temp = fact[n - c] * fact[c - 1]
			dp2[j] = dp2[i] * (fact[c] * fact[n - c - 1]) * pow(temp, mod - 2, mod) % mod
			g2[j].remove(i)
			q.append(j)
		else:
			q.pop()
			if len(q) > 1:
				child[q[-1]] += child[i]
	for i in dp2:
		print(i)
main()


from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
n = int(input())
G = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	G[a].append(b)
	G[b].append(a)
mod = 10 ** 9 + 7
queue = deque()
queue.append(0)
parent = [-1] * n
parent[0] = 0
while queue:
	now = queue.popleft()
	for to in G[now]:
		if parent[to] == -1:
			parent[to] = now
			queue.append(to)
data1 = [[0, 0] for i in range(n)]

def factorial(N, MOD, r=True):
	fact = [1] * (N + 1)
	rfact = [1] * (N + 1)
	r = 1
	for i in range(1, N + 1):
		fact[i] = r = r * i % MOD
	rfact[N] = r = pow(fact[N], MOD - 2, MOD)
	for i in range(N, 0, -1):
		rfact[i - 1] = r = r * i % MOD
	if r:
		return (fact, rfact)
	else:
		return fact
(fact, rfact) = factorial(2 * 10 ** 5, mod)

def com(l):
	res = 1
	s = 0
	for x in l:
		res *= rfact[x]
		res %= mod
		s += x
	res *= fact[s]
	res %= mod
	return res

def dfs(now, pre):
	if data1[now] != [0, 0]:
		return
	if len(G[now]) == 1 and G[now][0] == pre:
		data1[now] = [1, 1]
		return
	(x, y) = (0, 1)
	child = []
	for to in G[now]:
		if pre == to:
			continue
		dfs(to, now)
		child.append(data1[to][1])
		y *= data1[to][0]
		y %= mod
	res = y * com(child)
	res %= mod
	data1[now] = [res, sum(child) + 1]
	return
dfs(0, -1)
ans = [data1[i][0] for i in range(n)]
que = deque()
que.append([0, 0])
while que:
	(now, pre) = que.popleft()
	for to in G[now]:
		if to == pre:
			continue
		ans[to] = ans[now] * data1[to][1] * pow(n - data1[to][1], mod - 2, mod)
		ans[to] %= mod
		que.append([to, now])
for x in ans:
	print(x)


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

class modfact(object):

	def __init__(self, n):
		fact = [1] * (n + 1)
		invfact = [1] * (n + 1)
		for i in range(1, n + 1):
			fact[i] = i * fact[i - 1] % MOD
		invfact[n] = pow(fact[n], MOD - 2, MOD)
		for i in range(n - 1, -1, -1):
			invfact[i] = invfact[i + 1] * (i + 1) % MOD
		self.__fact = fact
		self.__invfact = invfact

	def inv(self, n):
		assert n > 0
		return self.__fact[n - 1] * self.__invfact[n] % MOD

	def fact(self, n):
		return self.__fact[n]

	def invfact(self, n):
		return self.__invfact[n]

	def comb(self, n, k):
		if k < 0 or n < k:
			return 0
		return self.__fact[n] * self.__invfact[k] * self.__invfact[n - k] % MOD

	def perm(self, n, k):
		if k < 0 or n < k:
			return 0
		return self.__fact[n] * self.__invfact[n - k] % MOD

def resolve():
	n = int(input())
	mf = modfact(n)
	E = [[] for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		u -= 1
		v -= 1
		E[u].append(v)
		E[v].append(u)
	dp = [1] * n
	size = [1] * n
	stack = [(~0, -1), (0, -1)]
	while stack:
		(v, p) = stack.pop()
		if v >= 0:
			for nv in E[v]:
				if nv == p:
					continue
				stack.append((~nv, v))
				stack.append((nv, v))
		else:
			v = ~v
			for nv in E[v]:
				if nv == p:
					continue
				size[v] += size[nv]
				dp[v] *= dp[nv] * mf.invfact(size[nv])
				dp[v] %= MOD
			dp[v] *= mf.fact(size[v] - 1)
			dp[v] %= MOD

	def rerooting(v, p):
		if p == -1:
			return
		dp[p] *= mf.fact(size[p] - size[v] - 1) * mf.invfact(size[p] - 1) * mf.fact(size[v]) * pow(dp[v], MOD - 2, MOD)
		dp[p] %= MOD
		size[p] -= size[v]
		size[v] += size[p]
		dp[v] *= mf.fact(size[v] - 1) * mf.invfact(size[v] - size[p] - 1) * dp[p] * mf.invfact(size[p])
		dp[v] %= MOD
	ans = [None] * n
	stack = [(0, -1)]
	while stack:
		(v, p) = stack.pop()
		if v >= 0:
			rerooting(v, p)
			ans[v] = dp[v]
			for nv in E[v]:
				if nv == p:
					continue
				stack.append((~nv, v))
				stack.append((nv, v))
		else:
			rerooting(p, ~v)
	print(*ans, sep='\n')
resolve()


import sys
sys.setrecursionlimit(1000000)

def input():
	return sys.stdin.readline()
n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = [int(i) - 1 for i in input().split()]
	e[a].append(b)
	e[b].append(a)
mod = 10 ** 9 + 7
kkai = [1]
for i in range(1, 2 * 10 ** 5):
	kkai.append(kkai[-1] * i % mod)

def kai(x, p=mod):
	return kkai[x]

def comb(a, b, p=mod):
	if a < 0 or b < 0:
		return 0
	elif a < b:
		return 0
	if b == 0:
		return 1
	c = 1
	c *= kai(a, p)
	c *= pow(kai(b, p), p - 2, p)
	c *= pow(kai(a - b, p), p - 2, p)
	return c % p
child = [0] * n

def dfs1(i=0, r=-1):
	s = 1
	for j in e[i]:
		if j == r:
			continue
		s += dfs1(j, i)
	child[i] = s
	return s
dfs1()
a = [0] * n

def dfs2(i=0, r=-1):
	s = kai(child[i] - 1)
	t = 1
	for j in e[i]:
		if j == r:
			continue
		s *= dfs2(j, i)
		s %= mod
		t *= kai(child[j])
		t %= mod
	s *= pow(t, mod - 2, mod)
	s %= mod
	a[i] = s
	return s
dfs2()
b = [0] * n

def dfs3(i=0, r=-1):
	if r == -1:
		b[i] = a[i]
	else:
		s = b[r] * child[i] % mod
		s *= pow(n - child[i], mod - 2, mod)
		s %= mod
		b[i] = s
	for j in e[i]:
		if j == r:
			continue
		dfs3(j, i)
dfs3()
print('\n'.join(map(str, b)))


MOD = 10 ** 9 + 7
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	G[a].append(b)
	G[b].append(a)
factorial = [1]
for i in range(1, N + 1):
	factorial.append(factorial[-1] * i % MOD)
inv_factorial = [-1] * (N + 1)
inv_factorial[-1] = pow(factorial[-1], MOD - 2, MOD)
for i in reversed(range(N)):
	inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD
deg = [0] * N
parent = [0] * N
dp = [0] * N
ans = [0] * N
cnt_leaf = [0] * N

def dfs(v, p=-1):
	deg[v] = len(G[v])
	dp[v] = [0] * deg[v]
	res = 1
	cnt = 0
	for (i, e) in enumerate(G[v]):
		if e == p:
			parent[v] = i
			continue
		(a, b) = dfs(e, v)
		dp[v][i] = a * inv_factorial[b] % MOD
		cnt += b
		res *= dp[v][i]
		res %= MOD
	res *= factorial[cnt] % MOD
	cnt_leaf[v] = cnt
	return (res, cnt + 1)

def bfs(v, res_p=0, p=-1):
	if p != -1:
		dp[v][parent[v]] = res_p
	dpl = [1] * (deg[v] + 1)
	for (i, x) in enumerate(dp[v]):
		dpl[i + 1] = dpl[i] * x % MOD
	dpr = [1] * (deg[v] + 1)
	for i in range(deg[v] - 1, -1, -1):
		dpr[i] = dpr[i + 1] * dp[v][i] % MOD
	ans[v] = dpr[0] * factorial[N - 1] % MOD
	for (i, e) in enumerate(G[v]):
		if e == p:
			continue
		bfs(e, dpl[i] * dpr[i + 1] * pow(N - cnt_leaf[e] - 1, MOD - 2, MOD) % MOD, v)
dfs(0)
bfs(0)
print('\n'.join(map(str, ans)))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
MAX = 2 * 10 ** 5 + 100
fact = [0] * MAX
inv = [0] * MAX
finv = [0] * MAX
MOD = 10 ** 9 + 7

def C_init():
	fact[0] = 1
	fact[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, MAX):
		fact[i] = fact[i - 1] * i % MOD
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD

def C(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD

def dfs1(v, pv):
	nums = []
	res = 1
	for nv in G[v]:
		if nv == pv:
			continue
		(num, chi_res) = dfs1(nv, v)
		nums.append(num)
		res *= chi_res
		res %= MOD
	M = sum(nums)
	A1[v] = M + 1
	for num in nums:
		res *= C(M, num)
		res %= MOD
		M -= num
	A2[v] = res
	return (A1[v], A2[v])

def dfs2(v, pv):
	res = A3[pv] * pow(C(N - 1, A1[v]) * A2[v], MOD - 2, MOD) % MOD
	M = N - 1
	res *= C(M, N - A1[v])
	M -= N - A1[v]
	for nv in G[v]:
		if nv == pv:
			continue
		res *= A2[nv]
		res *= C(M, A1[nv])
		M -= A1[nv]
		res %= MOD
	A3[v] = res
	for nv in G[v]:
		if nv == pv:
			continue
		dfs2(nv, v)
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
C_init()
A1 = [-1] * N
A2 = [-1] * N
A3 = [-1] * N
dfs1(0, -1)
A3[0] = A2[0]
for nv in G[0]:
	dfs2(nv, 0)
for A3i in A3:
	print(A3i)


import sys
input = sys.stdin.readline

def main():
	mod = 1000000007
	inv = lambda x: pow(x, mod - 2, mod)
	n = int(input())
	Fact = [1]
	for i in range(1, n + 1):
		Fact.append(Fact[i - 1] * i % mod)
	Finv = [0] * (n + 1)
	Finv[-1] = inv(Fact[-1])
	for i in range(n - 1, -1, -1):
		Finv[i] = Finv[i + 1] * (i + 1) % mod
	Edges = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		a -= 1
		b -= 1
		Edges[a].append(b)
		Edges[b].append(a)
	Stack = [0]
	Par = [-1] * n
	Order = []
	while Stack:
		v = Stack.pop()
		Order.append(v)
		for c in Edges[v]:
			if c != Par[v]:
				Stack.append(c)
				Par[c] = v
	DP = [1] * n
	Size = [1] * n
	for v in Order[::-1]:
		DP[v] *= Fact[Size[v] - 1]
		DP[v] %= mod
		p = Par[v]
		if p == -1:
			continue
		Size[p] += Size[v]
		DP[p] *= DP[v] * Finv[Size[v]]
		DP[p] %= mod
	Ans = [0] * n
	Ans[0] = DP[0]
	for v in Order[1:]:
		p = Par[v]
		Ans[v] = Ans[p] * Size[v] * inv(n - Size[v]) % mod
	print(*Ans, sep='\n')
main()


from collections import deque
MOD = 10 ** 9 + 7

def solve(n, edge_list):
	factorial = [1] * n
	for i in range(1, n):
		factorial[i] = factorial[i - 1] * i % MOD
	factorial_inv = [1] * n
	factorial_inv[-1] = pow(factorial[-1], MOD - 2, MOD)
	for i in range(n - 2, 0, -1):
		factorial_inv[i] = factorial_inv[i + 1] * (i + 1) % MOD
	g = [[] for _ in range(n)]
	for i in range(n - 1):
		(a, b) = edge_list[i]
		g[a].append(b)
		g[b].append(a)
	order = []
	parent = [-1] * n
	parent[0] = 0
	children = [[] for _ in range(n)]
	queue = deque([0])
	while len(queue) > 0:
		p = queue.popleft()
		order.append(p)
		for q in g[p]:
			if parent[q] == -1:
				parent[q] = p
				children[p].append(q)
				queue.append(q)
	count_children_res = [-1] * n
	for x in order[::-1]:
		if len(children[x]) == 0:
			count_children_res[x] = 0
		else:
			r = len(children[x]) + sum([count_children_res[y] for y in children[x]])
			count_children_res[x] = r
	assign_children_res = [-1] * n
	for x in order[::-1]:
		if len(children[x]) == 0:
			assign_children_res[x] = 1
		else:
			r = factorial[count_children_res[x]]
			for y in children[x]:
				r *= assign_children_res[y]
				r *= factorial_inv[count_children_res[y] + 1]
				r %= MOD
			assign_children_res[x] = r
	assign_parents_res = [-1] * n
	assign_parents_res[0] = 1
	for x in order[1:]:
		p = parent[x]
		r = assign_children_res[p]
		r *= pow(assign_children_res[x], MOD - 2, MOD)
		r *= factorial[count_children_res[x] + 1]
		r *= factorial_inv[count_children_res[p]]
		r *= assign_parents_res[p]
		r *= factorial[n - count_children_res[x] - 2]
		r *= factorial_inv[n - count_children_res[p] - 1]
		r %= MOD
		assign_parents_res[x] = r
	res_list = [0] * n
	res_list[0] = assign_children_res[0]
	for i in range(1, n):
		res = factorial[n - 1]
		for j in children[i]:
			res *= assign_children_res[j]
			res *= factorial_inv[count_children_res[j] + 1]
			res %= MOD
		res *= assign_parents_res[i]
		res *= factorial_inv[n - 1 - count_children_res[i]]
		res %= MOD
		res_list[i] = res
	return res_list

def main():
	n = int(input())
	edge_list = []
	for _ in range(n - 1):
		(a, b) = list(map(int, input().split()))
		edge_list.append((a - 1, b - 1))
	res_list = solve(n, edge_list)
	for res in res_list:
		print(res)

def test():
	assert solve(3, [(0, 1), (0, 2)]) == [2, 1, 1]
	assert solve(2, [(0, 1)]) == [1, 1]
	assert solve(5, [(0, 1), (1, 2), (2, 3), (2, 4)]) == [2, 8, 12, 3, 3]
	assert solve(8, [(0, 1), (1, 2), (2, 3), (2, 4), (2, 5), (5, 6), (5, 7)]) == [40, 280, 840, 120, 120, 504, 72, 72]

def __starting_point():
	test()
	main()
__starting_point()


import sys
input = sys.stdin.readline
N = int(input())
vec = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	vec[a - 1].append(b - 1)
	vec[b - 1].append(a - 1)
mod = 10 ** 9 + 7
fac = [1]
for i in range(1, N + 1):
	fac.append(fac[-1] * i % mod)
inv = [pow(fac[-1], mod - 2, mod)]
for i in range(N, 0, -1):
	inv.append(inv[-1] * i % mod)
inv = inv[::-1]

def comb(n, r):
	return fac[n] * inv[n - r] * inv[r] % mod
pattern = [1] * N
subtree = [0] * N
stack = [(0, -1, 0)]
while stack:
	(cur, pre, op) = stack.pop()
	if op == 0:
		stack.append((cur, pre, 1))
		for nex in vec[cur]:
			if nex == pre:
				continue
			stack.append((nex, cur, 0))
	else:
		for nex in vec[cur]:
			pattern[cur] *= pattern[nex] * comb(subtree[cur] + subtree[nex], subtree[nex]) % mod
			pattern[cur] %= mod
			subtree[cur] += subtree[nex]
		subtree[cur] += 1
queue = [(0, -1)]
while queue:
	(cur, pre) = queue.pop()
	for nex in vec[cur]:
		if nex == pre:
			continue
		pattern[nex] = pattern[cur] * subtree[nex] * inv[N - subtree[nex]] * fac[N - subtree[nex] - 1] % mod
		queue.append((nex, cur))
for i in range(N):
	print(pattern[i])


def main():
	import sys
	input = sys.stdin.readline
	mod = 1000000007
	nmax = 2 * 10 ** 5 + 10
	fac = [0] * nmax
	finv = [0] * nmax
	inv = [0] * nmax
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, nmax):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod

	def comb(n, r):
		if n < r:
			return 0
		else:
			return fac[n] * (finv[r] * finv[n - r] % mod) % mod
	N = int(input())
	adj = [[] for _ in range(N + 1)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		adj[a].append(b)
		adj[b].append(a)

	def op(a, b):
		return (a[0] * b[0] % mod * comb(a[1] + b[1] + 1, a[1]) % mod, a[1] + b[1] + 1)
	ident_op = (1, -1)

	def cum_merge(a, b):
		return (a[0] * b[0] % mod * comb(a[1] + b[1], a[1]) % mod, a[1] + b[1])
	ident_cum_merge = (1, 0)

	def Rerooting(adj):
		N = len(adj) - 1
		st = [1]
		seen = [0] * (N + 1)
		seen[1] = 1
		par = [0] * (N + 1)
		child = [[] for _ in range(N + 1)]
		seq = []
		while st:
			v = st.pop()
			seq.append(v)
			for u in adj[v]:
				if not seen[u]:
					seen[u] = 1
					par[u] = v
					child[v].append(u)
					st.append(u)
		seq.reverse()
		dp = [ident_op] * (N + 1)
		left = [ident_cum_merge] * (N + 1)
		right = [ident_cum_merge] * (N + 1)
		for v in seq:
			tmp = ident_cum_merge
			for u in child[v]:
				left[u] = tmp
				tmp = op(tmp, dp[u])
			tmp = ident_cum_merge
			for u in reversed(child[v]):
				right[u] = tmp
				tmp = op(tmp, dp[u])
			dp[v] = tmp
		seq.reverse()
		from_par = [ident_op] * (N + 1)
		for v in seq:
			if v == 1:
				continue
			from_par[v] = op(cum_merge(left[v], right[v]), from_par[par[v]])
			dp[v] = op(dp[v], from_par[v])
		return dp
	dp = Rerooting(adj)
	for v in range(1, N + 1):
		print(dp[v][0])
main()


SIZE = 2 * 10 ** 5 + 5
MOD = 10 ** 9 + 7
SIZE += 1
inv = [0] * SIZE
fac = [0] * SIZE
inv[1] = 1
fac[0] = fac[1] = 1
for i in range(2, SIZE):
	inv[i] = MOD - MOD // i * inv[MOD % i] % MOD
	fac[i] = fac[i - 1] * i % MOD
import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
read = sys.stdin.read
n = int(input())
ab = [int(i) - 1 for i in read().split()]
g = [[] for _ in range(n)]
M = iter(ab)
for (a, b) in zip(M, M):
	g[a].append(b)
	g[b].append(a)
order = []
parent = [-1] * n
q = [0]
while q:
	v = q.pop()
	order.append(v)
	for c in g[v]:
		if c != parent[v]:
			q.append(c)
			parent[c] = v
size = [1] * n
for i in order[n - 1:0:-1]:
	size[parent[i]] += size[i]
res = fac[n]
for i in range(n):
	res *= inv[size[i]]
	res %= MOD
ans = [0] * n
ans[0] = res
for c in order[1:]:
	v = parent[c]
	ans[c] = ans[v] * size[c] % MOD * inv[n - size[c]] % MOD
print(*ans, sep='\n')


from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 13

def LI():
	return list(map(int, sys.stdin.readline().split()))

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.readline().rstrip().split()

def S():
	return sys.stdin.readline().rstrip()

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]

def SRL(n):
	return [list(S()) for i in range(n)]

def MSRL(n):
	return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
n = I()
fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
	fac[j] = fac[j - 1] * j % mod
inv[n] = pow(fac[n], mod - 2, mod)
for j in range(n - 1, -1, -1):
	inv[j] = inv[j + 1] * (j + 1) % mod

def comb(n, r):
	if r > n or n < 0 or r < 0:
		return 0
	return fac[n] * inv[n - r] * inv[r] % mod
G = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = LI()
	G[a - 1] += [b - 1]
	G[b - 1] += [a - 1]
cnt = [-1] * n
par = [-1] * n

def f(x):
	ret = 1
	for y in G[x]:
		if par[x] == y:
			continue
		par[y] = x
		ret += f(y)
	cnt[x] = ret
	return ret
f(0)
D = [0] * n

def tree_dp(x):
	c = 1
	remain_v = cnt[x] - 1
	for y in G[x]:
		if y == par[x]:
			continue
		c = c * tree_dp(y) * comb(remain_v, cnt[y]) % mod
		remain_v -= cnt[y]
	D[x] = c
	if x:
		return c
tree_dp(0)
ans = [0] * n
ans[0] = D[0]
q = deque([0])
while q:
	e = q.popleft()
	for d in G[e]:
		if d == par[e]:
			continue
		ans[d] = pow(comb(n - 1, cnt[d]) * D[d], mod - 2, mod) * ans[e] * comb(n - 1, cnt[d] - 1) * D[d] % mod
		q += [d]
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	G[a].append(b)
	G[b].append(a)
mod = 10 ** 9 + 7
fact = [1] * N
fact_inv = [1] * N
for i in range(1, N):
	fact[i] = i * fact[i - 1] % mod
inv = lambda x: pow(x, mod - 2, mod)
fact_inv[N - 1] = inv(fact[N - 1])
for i in range(1, N)[::-1]:
	fact_inv[i - 1] = i * fact_inv[i] % mod
comb = lambda n, k: fact[n] * fact_inv[k] * fact_inv[n - k] % mod
dp = [1] * N
size = [0] * N

def dfs(par, v):
	for u in G[v]:
		if par == u:
			continue
		dfs(v, u)
		size[v] += size[u]
		dp[v] = dp[v] * dp[u] * fact_inv[size[u]] % mod
	dp[v] = dp[v] * fact[size[v]] % mod
	size[v] += 1
ans = [0] * N

def reroot(par, val_par, size_par, v):
	ans[v] = val_par * dp[v] * comb(N - 1, size_par) % mod
	for u in G[v]:
		if par == u:
			continue
		val = ans[v] * inv(dp[u] * comb(N - 1, size[u])) % mod
		reroot(v, val, N - size[u], u)
dfs(-1, 0)
reroot(-1, 1, 0, 0)
print(*ans, sep='\n')


import sys
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7
N = int(input())
ab = [list(map(int, input().split())) for i in range(N - 1)]
fact = [1, 1]
fact_inv = [1, 1]
tmp_inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % mod)
	tmp_inv.append(-tmp_inv[mod % i] * (mod // i) % mod)
	fact_inv.append(fact_inv[-1] * tmp_inv[-1] % mod)

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return fact[n] * fact_inv[r] * fact_inv[n - r] % mod

def inv(a, mod):
	return pow(a, mod - 2, mod)
graph = [[] for _ in range(N + 1)]
for (a, b) in ab:
	graph[a].append(b)
	graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if parent[x] == y:
			continue
		parent[y] = x
		stack.append(y)
size_d = [0] * (N + 1)
dp_d = [1] * (N + 1)
for v in order[::-1]:
	dp_d[v] *= fact[size_d[v]]
	dp_d[v] %= mod
	p = parent[v]
	s = size_d[v] + 1
	size_d[p] += s
	dp_d[p] *= fact_inv[s] * dp_d[v]
	dp_d[p] %= mod
size_u = [N - x - 1 for x in size_d]
dp_u = [1] * (N + 1)
for v in order[1:]:
	p = parent[v]
	x = dp_d[p] * inv(dp_d[v], mod)
	x *= fact_inv[size_d[p]] * fact[size_d[v] + 1]
	x *= fact[size_u[v] - 1] * fact_inv[size_u[p]]
	x *= dp_u[p]
	dp_u[v] = x % mod
for (xd, xu, sd, su) in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
	x = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % mod
	print(x)


from collections import deque
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
mod = 10 ** 9 + 7
N = n + 5
bikkuri = [0 for i in range(N)]
bikkuri[0] = 1
gyaku = [0 for i in range(N)]
gyaku[0] = 1
for i in range(1, N):
	bikkuri[i] = i * bikkuri[i - 1] % mod
	gyaku[i] = pow(bikkuri[i], mod - 2, mod)
graph = [[] for _ in range(n + 1)]
m = map(int, read().split())
AB = zip(m, m)
for (a, b) in AB:
	graph[a].append(b)
	graph[b].append(a)
par = [-1] * (n + 1)
que = deque([])
que.append(1)
topo = []
while que:
	v = que.popleft()
	topo.append(v)
	for u in graph[v]:
		if u == par[v]:
			continue
		par[u] = v
		graph[u].remove(v)
		que.append(u)
dp1 = [0] * (n + 1)
size = [0] * (n + 1)
edge_index = [{} for _ in range(n + 1)]
dpl = [[] for _ in range(n + 1)]
dpr = [[] for _ in range(n + 1)]
for v in topo[::-1]:
	dp1[v] = 1
	size[v] = 1
	for u in graph[v]:
		size[v] += size[u]
		dp1[v] *= dp1[u]
		dp1[v] *= gyaku[size[u]]
	temp = 1
	for i in range(len(graph[v])):
		u = graph[v][i]
		edge_index[v][u] = i
		temp *= dp1[u]
		temp %= mod
		temp *= gyaku[size[u]]
		temp %= mod
		dpl[v].append(temp)
	temp = 1
	for i in range(len(graph[v]))[::-1]:
		u = graph[v][i]
		temp *= dp1[u]
		temp *= gyaku[size[u]]
		temp %= mod
		dpr[v].append(temp)
	dp1[v] *= bikkuri[size[v] - 1]
	dp1[v] %= mod
ans = [0] * (n + 1)
dp2 = [0] * (n + 1)
for v in topo:
	if par[v] == -1:
		dp2[v] = 1
		ans[v] = dp1[v]
	else:
		dp2[v] = 1
		p = par[v]
		v_idx = edge_index[p][v]
		dp2[v] *= dp2[p] * gyaku[n - size[p]]
		dp2[v] *= bikkuri[n - size[v] - 1]
		dp2[v] %= mod
		if dpl[p]:
			if v_idx - 1 >= 0:
				dp2[v] *= dpl[p][v_idx - 1]
				dp2[v] %= mod
			if v_idx < len(graph[p]) - 1:
				dp2[v] *= dpr[p][len(graph[p]) - 2 - v_idx]
				dp2[v] %= mod
	ans[v] = bikkuri[n - 1]
	if dpl[v]:
		ans[v] *= dpl[v][-1]
	ans[v] *= dp2[v] * gyaku[n - size[v]]
	ans[v] %= mod
for i in range(1, n + 1):
	print(ans[i])


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
MOD = 10 ** 9 + 7

def facinv(N):
	(fac, finv, inv) = ([0] * (N + 1), [0] * (N + 1), [0] * (N + 1))
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, N + 1):
		fac[i] = fac[i - 1] * i % MOD
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD
	return (fac, finv, inv)

def dfs(v, p):
	connect[v] = len(G[v])
	dp[v] = [1] * connect[v]
	sizdp[v] = [0] * connect[v]
	for i in range(connect[v]):
		nv = G[v][i]
		if nv == p:
			p_i[v] = i
			continue
		(R, siz) = dfs(nv, v)
		dp[v][i] = R
		size[v] += siz
		sizdp[v][i] = siz
	res = fac[size[v] - 1]
	for i in range(connect[v]):
		if G[v][i] == p:
			continue
		res = res * dp[v][i] % MOD * finv[sizdp[v][i]] % MOD
	return (res, size[v])

def reroot(v, res_p, p):
	if p != -1:
		dp[v][p_i[v]] = res_p
		sizdp[v][p_i[v]] = N - size[v]
	ans[v] = fac[N - 1]
	for i in range(connect[v]):
		ans[v] = ans[v] * dp[v][i] % MOD * finv[sizdp[v][i]] % MOD
	dp_L = [1] * (connect[v] + 1)
	dp_R = [1] * (connect[v] + 1)
	for i in range(connect[v]):
		dp_L[i + 1] = dp_L[i] * dp[v][i] % MOD * finv[sizdp[v][i]] % MOD
	for i in reversed(range(connect[v])):
		dp_R[i] = dp_R[i + 1] * dp[v][i] % MOD * finv[sizdp[v][i]] % MOD
	for i in range(connect[v]):
		nv = G[v][i]
		if nv == p:
			continue
		reroot(nv, fac[N - size[nv] - 1] * dp_L[i] * dp_R[i + 1] % MOD, v)
N = int(input())
(fac, finv, inv) = facinv(N)
G = [[] for i in range(N)]
for i in range(N - 1):
	(x, y) = map(lambda x: int(x) - 1, input().split())
	G[x].append(y)
	G[y].append(x)
dp = [[] for i in range(N)]
sizdp = [[] for i in range(N)]
connect = [-1] * N
size = [1] * N
p_i = [-1] * N
dp_L = [[] for i in range(N)]
dp_R = [[] for i in range(N)]
ans = [1] * N
dfs(0, -1)
reroot(0, 1, -1)
print(*ans, sep='\n')


def main():
	n = int(input())
	ab = [list(map(int, input().split())) for _ in [0] * (n - 1)]
	g = [[] for _ in [0] * n]
	[g[a - 1].append(b - 1) for (a, b) in ab]
	[g[b - 1].append(a - 1) for (a, b) in ab]
	mod = 10 ** 9 + 7
	fact = [1, 1]
	for i in range(2, n + 1):
		fact.append(fact[-1] * i % mod)

	def inv_n(n):
		return pow(n, mod - 2, mod)

	def nCr(n, r, mod=10 ** 9 + 7):
		return pow(fact[n - r] * fact[r] % mod, mod - 2, mod) * fact[n] % mod

	class rerooting:

		def __init__(self, tree, ini):

			def merge(a, b):
				return a * b % mod

			def adj_bu(a, i):
				return a * inv_n(size[i]) % mod

			def adj_td(a, i, p):
				return a * inv_n(n - size[i]) % mod

			def adj_fin(a, i):
				return a * fact[n - 1] % mod
			T = [set(i) for i in tree]
			P = [-1] * n
			q = [0]
			order = []
			while q:
				i = q.pop()
				order.append(i)
				for a in T[i]:
					if a != P[i]:
						P[a] = i
						T[a].remove(i)
						q.append(a)
			T = [list(i) for i in T]
			size = [1] * n
			for i in order[1:][::-1]:
				size[P[i]] += size[i]
			ME = [ini] * n
			DP = [0] * n
			for i in order[1:][::-1]:
				DP[i] = adj_bu(ME[i], i)
				p = P[i]
				ME[p] = merge(ME[p], DP[i])
			DP[order[0]] = adj_fin(ME[order[0]], order[0])
			TD = [ini] * n
			for i in order:
				ac = TD[i]
				for j in T[i]:
					TD[j] = ac
					ac = merge(ac, DP[j])
				ac = ini
				for j in T[i][::-1]:
					TD[j] = adj_td(merge(TD[j], ac), j, i)
					ac = merge(ac, DP[j])
					DP[j] = adj_fin(merge(ME[j], TD[j]), j)
			for i in DP:
				print(i)
	rerooting(g, 1)
main()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
U = 2 * 10 ** 5
MOD = 10 ** 9 + 7
fact = [1] * (U + 1)
fact_inv = [1] * (U + 1)
for i in range(1, U + 1):
	fact[i] = fact[i - 1] * i % MOD
fact_inv[U] = pow(fact[U], MOD - 2, MOD)
for i in range(U, 0, -1):
	fact_inv[i - 1] = fact_inv[i] * i % MOD
n = int(input())
T = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	T[a].append(b)
	T[b].append(a)
size = [0] * n
par = [-1] * n
dp1 = [-1] * n
dp2 = [-1] * n

def dfs1(p, v):
	if dp1[v] != -1:
		return dp1[v]
	temp = 1
	s = 1
	for nv in T[v]:
		if nv == p:
			continue
		temp *= dfs1(v, nv)
		temp *= fact_inv[size[nv]]
		temp %= MOD
		par[nv] = v
		s += size[nv]
	size[v] = s
	temp *= fact[s - 1]
	temp %= MOD
	dp1[v] = temp
	return temp
dfs1(-1, 0)

def dfs2(v):
	if v == 0:
		return dp1[0]
	if dp2[v] != -1:
		return dp2[v]
	temp = dfs2(par[v])
	temp *= fact[n - size[v] - 1]
	temp *= fact[size[v]]
	temp %= MOD
	temp *= fact_inv[size[v] - 1]
	temp *= fact_inv[n - size[v]]
	temp %= MOD
	dp2[v] = temp
	return temp
for i in range(n):
	print(dfs2(i))


import sys
input = sys.stdin.readline
N = int(input())
E = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	E[a].append(b)
	E[b].append(a)
mod = 10 ** 9 + 7
FACT = [1]
for i in range(1, 2 * 10 ** 5 + 1):
	FACT.append(FACT[-1] * i % mod)
FACT_INV = [pow(FACT[-1], mod - 2, mod)]
for i in range(2 * 10 ** 5, 0, -1):
	FACT_INV.append(FACT_INV[-1] * i % mod)
FACT_INV.reverse()

def Combi(a, b):
	if 0 <= b <= a:
		return FACT[a] * FACT_INV[b] * FACT_INV[a - b] % mod
	else:
		return 0
TOP_SORT = []
Q = [1]
P = [-1] * (N + 1)
P[1] = 0
P[0] = 0
while Q:
	x = Q.pop()
	TOP_SORT.append(x)
	for to in E[x]:
		if P[to] == -1:
			P[to] = x
			Q.append(to)
Children = [1] * (N + 1)
ANS_UP = [1] * (N + 1)
for x in TOP_SORT[::-1]:
	sumchild = 0
	for to in E[x]:
		if to == P[x]:
			continue
		sumchild += Children[to]
		ANS_UP[x] = ANS_UP[x] * Combi(sumchild, Children[to]) % mod
	Children[P[x]] += Children[x]
	ANS_UP[P[x]] = ANS_UP[P[x]] * ANS_UP[x] % mod
ANS_DOWN = [1] * (N + 1)
for x in TOP_SORT:
	if x == 1:
		continue
	ANS_DOWN[x] = ANS_DOWN[P[x]] * ANS_UP[P[x]] * Combi(N - Children[x] - 1, N - Children[P[x]]) * pow(ANS_UP[x], mod - 2, mod) * pow(Combi(Children[P[x]] - 1, Children[x]), mod - 2, mod) % mod
for i in range(1, N + 1):
	if i == 1:
		print(ANS_UP[1])
	else:
		ANS = ANS_DOWN[i] % mod
		sumchild = 0
		for to in E[i]:
			if to == P[i]:
				sumchild += N - Children[i]
				ANS = ANS * Combi(sumchild, N - Children[i]) % mod
			else:
				sumchild += Children[to]
				ANS = ANS * ANS_UP[to] * Combi(sumchild, Children[to]) % mod
		print(ANS)


def hoge():
	import sys
	input = lambda : sys.stdin.readline().rstrip()
	sys.setrecursionlimit(max(1000, 10 ** 9))
	from collections import defaultdict
	n = int(input())
	ns = defaultdict(set)
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		ns[u - 1].add(v - 1)
		ns[v - 1].add(u - 1)
	M = 10 ** 9 + 7
	N = n
	g1 = [None] * (N + 1)
	g2 = [None] * (N + 1)
	inverse = [None] * (N + 1)
	g1[0] = g1[1] = g2[0] = g2[1] = 1
	(inverse[0], inverse[1]) = [0, 1]
	for i in range(2, N + 1):
		g1[i] = g1[i - 1] * i % M
		inverse[i] = -inverse[M % i] * (M // i) % M
		g2[i] = g2[i - 1] * inverse[i] % M
	ans = {}
	prevs = {}
	out = [None] * n

	def sub(i, j, prev):
		prevs[i, j] = prev
		if (i, j) in ans:
			return ans[i, j]
		if len(ns[j]) == 1 and i in ns[j]:
			ans[i, j] = (1, 1)
			return (1, 1)
		count = 1
		sum_size = 0
		for k in ns[j]:
			if k == i:
				continue
			(val, size) = sub(j, k, i)
			count = count * val % M
			count = count * g2[size] % M
			sum_size += size
		count = count * g1[sum_size] % M
		ans[i, j] = (count, sum_size + 1)
		return (count, sum_size + 1)

	def sub2(i, j, q):
		for k in ns[j]:
			if k == i:
				continue
			if (k, j) in ans:
				continue
			(tmp_count, tmp_size) = ans[j, k]
			(total_count, total_size) = ans[prevs[j, k], j]
			(prev_count, prev_size) = ans[j, i]
			new_size = total_size - tmp_size + prev_size
			new_count = total_count * g2[total_size - 1] * g1[new_size - 1] % M
			new_count = new_count * prev_count * pow(tmp_count, M - 2, M) % M
			new_count = new_count * g2[prev_size] * g1[tmp_size] % M
			ans[k, j] = (new_count, new_size)
			val = tmp_count
			val = val * new_count * g1[new_size + tmp_size - 1] * g2[tmp_size - 1] * g2[new_size] % M
			out[k] = val
			q.appendleft((j, k))
	sub(-1, 0, None)
	ans[0, -1] = (1, 0)
	from queue import deque
	q = deque()
	q.appendleft((-1, 0))
	while q:
		(u, v) = q.pop()
		sub2(u, v, q)
	u = 0
	count = 1
	sum_size = 0
	for k in ns[u]:
		(val, size) = ans[u, k]
		count = count * val % M
		count = count * g2[size] % M
		sum_size += size
	count = count * g1[sum_size] % M
	out[0] = count
	return out
out = hoge()
print('\n'.join(map(str, out)))


from functools import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
M = 10 ** 9 + 7

@lru_cache(maxsize=None)
def mod_inv(a):
	(b, x, y) = (M, 1, 0)
	while a != 1:
		((d, a), b) = (divmod(b, a), a)
		(x, y) = (y - d * x, x)
	return x % M

@lru_cache(maxsize=None)
def calc_subtree(v):
	ret = 1
	size = 1
	for child in Edge[v]:
		Edge[child].remove(v)
		(r, s) = calc_subtree(child)
		ret = ret * r % M
		size += s
	ret = ret * size % M
	return (ret, size)
ans = {}

def set_ans(v, a):
	ans[v] = a
	for child in Edge[v]:
		n = calc_subtree(child)[1]
		set_ans(child, ans[v] * n * mod_inv(N - n) % M)
N = int(input())
Edge = defaultdict(set)
fact = N
for i in range(1, N):
	fact = fact * i % M
	(a, b) = map(int, input().split())
	Edge[a].add(b)
	Edge[b].add(a)
set_ans(1, mod_inv(calc_subtree(1)[0]) * fact % M)
for i in range(1, N + 1):
	print(ans[i])


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():

	def dfs(x):
		fx = ans[x]
		nf = fx * inv[s[x] - 1] % mod
		sx = s[x]
		for y in v[x]:
			sy = s[y]
			nsx = sx - sy
			nsy = s[x]
			if ans[y] == None:
				fy = nf * s[y] * f[nsy - 1] * p[nsx] % mod
				ans[y] = fy
				s[x] = nsx
				s[y] = nsy
				dfs(y)
				s[x] = sx
				s[y] = sy
	n = I()
	f = [1]
	for i in range(1, n + 1):
		f.append(f[-1] * i % mod)
	inv = [None] * (n + 1)
	inv[n] = pow(f[n], mod - 2, mod)
	for i in range(n)[::-1]:
		inv[i] = inv[i + 1] * (i + 1) % mod
	v = [[] for i in range(n)]
	for i in range(n - 1):
		(a, b) = LI()
		a -= 1
		b -= 1
		v[a].append(b)
		v[b].append(a)
	d = [0] * n
	d[0] = 1
	q = deque([0])
	p = [None] * n
	while q:
		x = q.popleft()
		nd = d[x] + 1
		for y in v[x]:
			if not d[y]:
				d[y] = nd
				p[y] = x
				q.append(y)
	V = list(range(n))
	V.sort(key=lambda x: -d[x])
	m = d[V[0]]
	s = [0] * n
	res = 1
	for i in V:
		j = p[i]
		s[i] += 1
		if j != None:
			s[j] += s[i]
			res *= inv[s[i]]
		if d[i] == m:
			continue
		res *= f[s[i] - 1]
		res %= mod
	ans = [None] * n
	ans[0] = res
	p = [pow(i, mod - 2, mod) for i in range(n + 1)]
	dfs(0)
	for i in ans:
		print(i)
	return
solve()


import sys
sys.setrecursionlimit(1234567890)
(n, *L) = map(int, open(0).read().split())
mod = 10 ** 9 + 7
con = [[] for _ in range(n + 1)]
sz = [1] * (n + 1)
par = [0] * (n + 1)
for (s, t) in zip(*[iter(L)] * 2):
	con[s] += (t,)
	con[t] += (s,)

def prepare(m, mod=10 ** 9 + 7):
	fac = [1] * (m + 1)
	inv = [1] * (m + 1)
	for i in range(1, m + 1):
		fac[i] = fac[i - 1] * i % mod
	inv[-1] = pow(fac[-1], mod - 2, mod)
	for i in range(m - 1, -1, -1):
		inv[i] = inv[i + 1] * (i + 1) % mod
	return (fac, inv)
(fac, inv) = prepare(n)

def dfs1(cur, pre):
	par[cur] = pre
	for nxt in con[cur]:
		if nxt != pre:
			dfs1(nxt, cur)
			sz[cur] += sz[nxt]
			dp1[cur] *= dp1[nxt] * inv[sz[nxt]] % mod
			dp1[cur] %= mod
	dp1[cur] *= fac[sz[cur] - 1]
	dp1[cur] %= mod

def dfs2(cur, pre):
	dp2[cur] *= dp1[cur] * inv[sz[cur] - 1] % mod
	dp2[cur] %= mod
	dp2[cur] *= fac[n - 1]
	dp2[cur] %= mod
	for nxt in con[cur]:
		if nxt != pre:
			dp2[nxt] = fac[sz[nxt]] * pow(n - sz[nxt], mod - 2, mod) * pow(dp1[nxt], mod - 2, mod) * dp2[cur] * inv[n - 1] % mod
			dfs2(nxt, cur)
dp1 = [1] * (n + 1)
dfs1(1, 0)
dp2 = [1] * (n + 1)
dfs2(1, 0)
print(*dp2[1:], sep='\n')


from fractions import gcd
import sys
sys.setrecursionlimit(4100000)

def os():
	return input()

def oi():
	return int(input())

def oli():
	return map(int, input().split())

def olai():
	return list(map(int, input().split()))

def olas():
	return list(input().split())

def mlai(L):
	return [int(input()) for _ in range(L)]

def mlas(L):
	return [input() for _ in range(L)]

def ar(a, b, c=-1, d=-1, INIT=0):
	if c == -1:
		return [[INIT] * b for _ in range(a)]
	if d == -1:
		return [[[INIT] * c for _ in range(b)] for __ in range(a)]
	return [[[[INIT] * d for _ in range(c)] for __ in range(b)] for ___ in range(a)]

def lcm(a, b):
	return a * b // gcd(a, b)
P = 10 ** 9 + 7
N = 200001
inv = [0] + [1]
finv = [1] + [1]
fac = [1] + [1]
for i in range(2, N):
	inv += [inv[P % i] * (P - int(P / i)) % P]
	fac += [fac[i - 1] * i % P]
	finv += [finv[i - 1] * inv[i] % P]

def comb(a, b):
	if a < b or b < 0:
		return 0
	return fac[a] * (finv[b] * finv[a - b] % P) % P

class T:
	num = 1
	child = 0

	def __init__(self, a, b):
		self.num = a
		self.child = b
zero = T(1, 0)

def step(x):
	return T(x.num, x.child + 1)

def merge(x, y):
	return T(x.num * y.num * comb(x.child + y.child, x.child) % P, x.child + y.child)
G = [[] for _ in range(200001)]
down_data = [zero for _ in range(200001)]
dat = [zero for _ in range(200001)]

def dfs(now, parent):
	cnt = 0
	for to in G[now]:
		if to == parent:
			continue
		cnt += 1
		dfs(to, now)
		down_data[now] = merge(down_data[now], step(down_data[to]))

def dfs_rev(now, parent, rev):
	left = []
	right = []
	cnt = 0
	for to in G[now]:
		if to == parent:
			continue
		if len(left) == 0:
			left.append(step(down_data[to]))
		else:
			left.append(merge(left[cnt - 1], step(down_data[to])))
		cnt += 1
	cnt = 0
	for to in reversed(G[now]):
		if to == parent:
			continue
		if len(right) == 0:
			right.append(step(down_data[to]))
		else:
			right.append(merge(right[cnt - 1], step(down_data[to])))
		cnt += 1
	cnt = 0
	dat[now] = merge(rev, down_data[now])
	for to in G[now]:
		if to == parent:
			continue
		x = zero if cnt == 0 else left[cnt - 1]
		y = zero if cnt == len(right) - 1 else right[len(right) - 2 - cnt]
		dfs_rev(to, now, step(merge(rev, merge(x, y))))
		cnt += 1

def main():
	n = oi()
	for i in range(n - 1):
		(a, b) = oli()
		G[a].append(b)
		G[b].append(a)
	root = -1
	for i in range(1, n + 1):
		if len(G[i]) == 1:
			root = i
			break
	dfs(root, -1)
	dfs_rev(root, -1, zero)
	for i in range(1, n + 1):
		print(dat[i].num)
main()


import sys
sys.setrecursionlimit(10 ** 6)

def inverse(a, mod):
	return pow(a, mod - 2, mod)

def modfac(n, MOD):
	f = 1
	factorials = [1]
	for m in range(1, n + 1):
		f *= m
		f %= MOD
		factorials.append(f)
	inv = pow(f, MOD - 2, MOD)
	invs = [1] * (n + 1)
	invs[n] = inv
	for m in range(n, 1, -1):
		inv *= m
		inv %= MOD
		invs[m - 1] = inv
	return (factorials, invs)

def modnCr(n, r, mod, fac, inv):
	return fac[n] * inv[n - r] * inv[r] % mod
N = int(input())
mod = 10 ** 9 + 7
(fac, inv) = modfac(N, mod)
lis = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = list(map(int, input().split()))
	a -= 1
	b -= 1
	lis[a].append(b)
	lis[b].append(a)
plis = [i for i in range(N)]
chnum = [0] * N
mulis = [0] * N

def dfs(v, p):
	rch = 1
	rmu = 1
	chlis = []
	for nex in lis[v]:
		if nex != p:
			(ch, mu) = dfs(nex, v)
			rch += ch
			rmu *= mu
			rmu %= mod
			chlis.append(ch)
	nsum = sum(chlis)
	for i in range(len(chlis)):
		rmu *= modnCr(nsum, chlis[i], mod, fac, inv)
		rmu %= mod
		nsum -= chlis[i]
	plis[v] = p
	chnum[v] = rch
	mulis[v] = rmu
	return (rch, rmu)
ans = [None] * N
(temp, ans[0]) = dfs(0, 0)

def dfs2(v, p):
	if v != 0:
		vn = chnum[v]
		mn = mulis[v]
		ans[v] = ans[p] * modnCr(N - 1, N - vn, mod, fac, inv) * inverse(modnCr(N - 1, vn, mod, fac, inv), mod) % mod
	for nex in lis[v]:
		if nex != p:
			dfs2(nex, v)
dfs2(0, 0)
print('\n'.join(map(str, ans)))


def main():
	import sys
	sys.setrecursionlimit(10 ** 9)
	input = sys.stdin.readline
	mod = 1000000007

	def make_fact(n):
		fact = [1] * (n + 1)
		ifact = [1] * (n + 1)
		for i in range(1, n + 1):
			fact[i] = fact[i - 1] * i % mod
		ifact[n] = pow(fact[n], mod - 2, mod)
		for i in range(n, 0, -1):
			ifact[i - 1] = ifact[i] * i % mod
		return (fact, ifact)
	(fact, ifact) = make_fact(2000002)

	def comb(n, k):
		if k < 0 or k > n:
			return 0
		return fact[n] * ifact[k] * ifact[n - k] % mod
	N = int(input())
	AB = [tuple(map(int, input().split())) for _ in range(N - 1)]
	graph = [[] for _ in range(N + 1)]
	for (a, b) in AB:
		graph[a].append(b)
		graph[b].append(a)
	root = 1
	parent = [0] * (N + 1)
	order = []
	stack = [root]
	while stack:
		x = stack.pop()
		order.append(x)
		for y in graph[x]:
			if y == parent[x]:
				continue
			parent[y] = x
			stack.append(y)
	size_d = [0] * (N + 1)
	dp_d = [1] * (N + 1)
	for v in order[::-1]:
		dp_d[v] *= fact[size_d[v]]
		dp_d[v] %= mod
		p = parent[v]
		s = size_d[v] + 1
		size_d[p] += s
		dp_d[p] *= ifact[s] * dp_d[v]
		dp_d[p] %= mod
	size_u = [N - 2 - x for x in size_d]
	dp_u = [1] * (N + 1)
	for v in order[1:]:
		p = parent[v]
		x = dp_d[p]
		x *= dp_u[p]
		x *= ifact[size_d[p]]
		x *= fact[size_d[v] + 1]
		x *= pow(dp_d[v], mod - 2, mod)
		x *= fact[size_u[v]]
		x *= ifact[size_u[p] + 1]
		dp_u[v] = x % mod
	for (xd, xu, sd, su) in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
		su += 1
		x = xd * xu * comb(sd + su, su) % mod
		print(x)
main()


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	g = [[] for _ in range(n)]
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		g[a].append(b)
		g[b].append(a)
	mod = 10 ** 9 + 7
	N = 10 ** 6
	g1 = [1, 1]
	g2 = [1, 1]
	inverse = [0, 1]
	for i in range(2, N + 1):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	s = []
	s.append(0)
	parent = [-1] * n
	order = []
	while s:
		v = s.pop()
		order.append(v)
		for u in g[v]:
			if u == parent[v]:
				continue
			parent[u] = v
			s.append(u)
	dp = [1] * n
	c = [0] * n
	order.reverse()
	for v in order:
		dp[v] *= g1[c[v]]
		dp[v] %= mod
		c[v] += 1
		if parent[v] == -1:
			continue
		c[parent[v]] += c[v]
		dp[parent[v]] *= dp[v] * g2[c[v]]
		dp[parent[v]] %= mod
	order.reverse()
	ans = [0] * n
	for v in order:
		ans[v] = dp[v]
		for u in g[v]:
			if u == parent[v]:
				continue
			dp[u] *= ans[v] * g2[c[v] - 1] * g1[c[v] - 1 - c[u]] * g1[c[u]] * pow(dp[u], mod - 2, mod)
			dp[u] *= g2[c[u] - 1]
			dp[u] *= g1[c[v] - 1]
			dp[u] *= g2[c[v] - c[u]]
			dp[u] %= mod
			c[u] = c[v]
	for i in range(n):
		print(ans[i] % mod)

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(500000)
from collections import deque
MOD = 10 ** 9 + 7
INF = float('inf')

def inv(n):
	return pow(n, MOD - 2, MOD)
kaijo_memo = []

def kaijo(n):
	if len(kaijo_memo) > n:
		return kaijo_memo[n]
	if len(kaijo_memo) == 0:
		kaijo_memo.append(1)
	while len(kaijo_memo) <= n:
		kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
	return kaijo_memo[n]
gyaku_kaijo_memo = []

def gyaku_kaijo(n):
	if len(gyaku_kaijo_memo) > n:
		return gyaku_kaijo_memo[n]
	if len(gyaku_kaijo_memo) == 0:
		gyaku_kaijo_memo.append(1)
	while len(gyaku_kaijo_memo) <= n:
		gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD)
	return gyaku_kaijo_memo[n]

def nCr(n, r):
	if n == r:
		return 1
	if n < r or r < 0:
		return 0
	ret = 1
	ret = ret * kaijo(n) % MOD
	ret = ret * gyaku_kaijo(r) % MOD
	ret = ret * gyaku_kaijo(n - r) % MOD
	return ret
N = int(input())
graph = [[] for i in range(N)]
for _ in range(N - 1):
	(a, b) = list(map(int, input().split()))
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
p = [-1 for i in range(N)]
a = [[] for i in range(N)]
shori = []

def bfs(graph, start):
	N = len(graph)
	d = [INF] * N
	d[start] = 0
	q = deque([start])
	while q:
		u = q.popleft()
		shori.append(u)
		for v in graph[u]:
			if d[v] != INF:
				continue
			d[v] = d[u] + 1
			p[v] = u
			a[u].append(v)
			q.append(v)
	return d
bfs(graph, 0)
size = [0 for i in range(N)]

def calc_size(x):
	if size[x]:
		return size[x]
	temp = 1
	for y in a[x]:
		temp += calc_size(y)
	size[x] = temp
	return size[x]
calc_size(0)
narabi = [0 for i in range(N)]

def calc_narabi(x):
	if narabi[x]:
		return narabi[x]
	temp = kaijo(size[x] - 1)
	for y in a[x]:
		temp *= gyaku_kaijo(size[y]) * calc_narabi(y)
		temp %= MOD
	narabi[x] = temp
	return narabi[x]
calc_narabi(0)
pnarabi = [1 for i in range(N)]
for i in shori[1:]:
	pnarabi[i] = narabi[p[i]] * inv(narabi[i]) * inv(nCr(size[p[i]] - 1, size[i])) * pnarabi[p[i]] * nCr(N - 1 - size[i], N - size[p[i]])
	pnarabi[i] %= MOD
for i in shori[1:]:
	temp = narabi[i] * nCr(N - 1, size[i] - 1) * pnarabi[i]
	temp %= MOD
	narabi[i] = temp
print(*narabi, sep='\n')


import sys
input = sys.stdin.readline
from collections import deque

def main():
	mod = 1000000007
	inv = lambda x: pow(x, mod - 2, mod)
	n = int(input())
	Fact = [1]
	for i in range(1, n + 1):
		Fact.append(Fact[i - 1] * i % mod)
	Finv = [0] * (n + 1)
	Finv[-1] = inv(Fact[-1])
	for i in range(n - 1, -1, -1):
		Finv[i] = Finv[i + 1] * (i + 1) % mod
	Edges = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		a -= 1
		b -= 1
		Edges[a].append(b)
		Edges[b].append(a)
	Stack = [0]
	Par = [-1] * n
	Order = []
	while Stack:
		v = Stack.pop()
		Order.append(v)
		for c in Edges[v]:
			if c != Par[v]:
				Stack.append(c)
				Par[c] = v
	DP = [1] * n
	Size = [1] * n
	for v in Order[::-1]:
		DP[v] *= Fact[Size[v] - 1]
		DP[v] %= mod
		p = Par[v]
		if p == -1:
			continue
		Size[p] += Size[v]
		DP[p] *= DP[v] * Finv[Size[v]]
		DP[p] %= mod
	Ans = [0] * n
	que = deque()
	que.append((0, -1, 1))
	while que:
		(v, par, par_cnt) = que.popleft()
		Left = [1]
		for to in Edges[v]:
			tmp = DP[to] * Finv[Size[to]]
			if to == par:
				tmp = par_cnt * Finv[n - Size[v]]
			Left.append(Left[-1] * tmp % mod)
		Right = [1]
		for to in reversed(Edges[v]):
			tmp = DP[to] * Finv[Size[to]]
			if to == par:
				tmp = par_cnt * Finv[n - Size[v]]
			Right.append(Right[-1] * tmp % mod)
		Ans[v] = Left[-1] * Fact[n - 1] % mod
		m = len(Edges[v])
		for (i, to) in enumerate(Edges[v]):
			if to != par:
				que.append((to, v, Left[i] * Right[m - i - 1] * Fact[n - Size[to] - 1] % mod))
	print(*Ans, sep='\n')
main()


import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, n, mod):
		self.f = [1]
		self.mod = mod
		for j in range(1, n + 1):
			self.f.append(self.f[-1] * j % mod)
		self.i = [pow(self.f[-1], mod - 2, mod)]
		for j in range(n, 0, -1):
			self.i.append(self.i[-1] * j % mod)
		self.i.reverse()

	def factorial(self, j):
		return self.f[j]

	def ifactorial(self, j):
		return self.i[j]

	def comb(self, n, k):
		return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0
N = int(input())
C = Factorial(N + 1, MOD)
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	G[a].append(b)
	G[b].append(a)
order = []
order_append = order.append
stack = [(0, -1)]
stack_pop = stack.pop
stack_append = stack.append
while stack:
	tmp = stack_pop()
	order_append(tmp)
	for next_ in G[tmp[0]]:
		if next_ == tmp[1]:
			continue
		stack_append((next_, tmp[0]))
size = [1] * N
dp = [1] * N
for (c, p) in order[::-1]:
	if c == 0:
		break
	size[p] += size[c]
for (c, p) in order[::-1]:
	dp[c] = dp[c] * C.factorial(size[c] - 1) % MOD
	if c == 0:
		break
	dp[p] = dp[p] * dp[c] % MOD * C.ifactorial(size[c]) % MOD
dp2 = [0] * N
dp2[0] = dp[0]
for (c, p) in order[1:]:
	tmp = dp2[p] * C.factorial(N - 1 - size[c]) % MOD * C.factorial(size[c]) % MOD
	red = tmp * C.ifactorial(N - 1) % MOD * pow(dp[c], MOD - 2, MOD) % MOD
	size_red = N - size[c]
	tmp = dp[c] * red % MOD * C.factorial(N - 1) % MOD
	dp2[c] = tmp * C.ifactorial(size[c] - 1) % MOD * C.ifactorial(size_red) % MOD
print(*dp2, sep='\n')


class Combination:

	def __init__(self, size, mod=10 ** 9 + 7):
		self.size = size + 2
		self.mod = mod
		self.fact = [1, 1] + [0] * size
		self.factInv = [1, 1] + [0] * size
		self.inv = [0, 1] + [0] * size
		for i in range(2, self.size):
			self.fact[i] = self.fact[i - 1] * i % self.mod
			self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
			self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

	def npr(self, n, r):
		if n < r or n < 0 or r < 0:
			return 0
		return self.fact[n] * self.factInv[n - r] % self.mod

	def ncr(self, n, r):
		if n < r or n < 0 or r < 0:
			return 0
		return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

	def nhr(self, n, r):
		return self.ncr(n + r - 1, n - 1)

	def factN(self, n):
		if n < 0:
			return 0
		return self.fact[n]
N = int(input())
MOD = 10 ** 9 + 7
comb = Combination(N + 100)
edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(fr, to) = map(int, input().split())
	edges[fr].append(to)
	edges[to].append(fr)
parent = [0] * (N + 1)
order = []
st = [1]
while st:
	now = st.pop()
	order.append(now)
	for to in edges[now]:
		if to == parent[now]:
			continue
		st.append(to)
		parent[to] = now
size = [1] * (N + 1)
for v in order[::-1]:
	size[parent[v]] += size[v]
dp = [1] * (N + 1)
for v in order[::-1]:
	dp[v] = dp[v] * comb.fact[size[v] - 1] % MOD
	dp[parent[v]] *= dp[v] * comb.factInv[size[v]]
ans = [1] * (N + 1)
dpL = [[] for _ in range(N + 1)]
dpR = [[] for _ in range(N + 1)]
eToI = [{to: i for (i, to) in enumerate(edges[v])} for v in range(N + 1)]
for v in order:
	pr = parent[v]
	M = len(edges[v])
	L = [1] * (M + 1)
	R = [1] * (M + 1)
	for (i, to) in enumerate(edges[v]):
		if to == pr:
			j = eToI[pr][v]
			L[i + 1] = L[i] * dpL[pr][j] * dpR[pr][j + 1] * comb.fact[N - size[v] - 1] * comb.factInv[N - size[v]] % MOD
		else:
			L[i + 1] = L[i] * dp[to] * comb.factInv[size[to]] % MOD
	for (i, to) in enumerate(edges[v][::-1]):
		if to == pr:
			j = eToI[pr][v]
			R[i + 1] = R[i] * dpL[pr][j] * dpR[pr][j + 1] * comb.fact[N - size[v] - 1] * comb.factInv[N - size[v]] % MOD
		else:
			R[i + 1] = R[i] * dp[to] * comb.factInv[size[to]] % MOD
	dpL[v] = L
	dpR[v] = R[::-1]
	ans[v] = R[-1] * comb.fact[N - 1] % MOD
print(*ans[1:], sep='\n')


from functools import reduce
p = 1000000007
cmod_max = 200000
ccache = []
inv_ccache = [None] * (cmod_max + 1)

def powmod(a, n):
	global p
	res = 1
	tmp = a
	while n > 0:
		if n & 1 == 1:
			res = res * tmp % p
		n = n // 2
		tmp = tmp * tmp % p
	return res

def invmod(n):
	return powmod(n, p - 2)

def cmod(n, r):
	global p
	global ccache
	global inv_ccache
	if len(ccache) == 0:
		ccache.append(1)
		for i in range(cmod_max):
			ccache.append(ccache[i] * (i + 1) % p)
		inv_ccache[cmod_max] = invmod(ccache[cmod_max])
		for i in range(cmod_max, 0, -1):
			inv_ccache[i - 1] = inv_ccache[i] * i % p
	if r > n or r < 0:
		return 0
	if r > n // 2:
		return cmod(n, n - r)
	return ccache[n] * inv_ccache[r] % p * inv_ccache[n - r] % p
n = int(input())
adj_of = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	adj_of[a - 1].append(b - 1)
	adj_of[b - 1].append(a - 1)
stack = [(0, -1)]
course = []
while len(stack) > 0:
	popped = stack.pop()
	course.append(popped)
	for adj in adj_of[popped[0]]:
		if adj != popped[1]:
			stack.append((adj, popped[0]))
sizes = [{} for _ in range(n)]
pattern_nums = [{} for _ in range(n)]
for step in reversed(course):
	size = 1
	pattern_num = 1
	for adj in adj_of[step[0]]:
		if adj != step[1]:
			size += sizes[adj][step[0]]
			pattern_num *= pattern_nums[adj][step[0]] * cmod(size - 1, sizes[adj][step[0]])
			pattern_num %= p
	sizes[step[0]][step[1]] = size
	pattern_nums[step[0]][step[1]] = pattern_num
ans = [None] * n
for step in course:
	if step[0] == 0:
		ans[0] = pattern_nums[0][-1]
		continue
	pattern_nums_step1_step0 = ans[step[1]] * invmod(cmod(n - 1, sizes[step[0]][step[1]]) * pattern_nums[step[0]][step[1]]) % p
	ans[step[0]] = pattern_nums[step[0]][step[1]] * pattern_nums_step1_step0 * cmod(n - 1, sizes[step[0]][step[1]] - 1) % p
for a in ans:
	print(a)


from collections import deque
mod = 10 ** 9 + 7
SIZE = 2 * 10 ** 5 + 1
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
(fact[0], fact[1]) = (1, 1)
inv[1] = 1
(finv[0], finv[1]) = (1, 1)
for i in range(2, SIZE):
	fact[i] = fact[i - 1] * i % mod
	inv[i] = mod - inv[mod % i] * (mod // i) % mod
	finv[i] = finv[i - 1] * inv[i] % mod

def nCr(n, r):
	if n < 0 or r < 0 or n < r:
		return 0
	return fact[n] * (finv[r] * finv[n - r] % mod) % mod
n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edges[a - 1].append(b - 1)
	edges[b - 1].append(a - 1)
root_to_leaf = []
parents = [0] * n
todo = deque([])
for to in edges[0]:
	todo.append([to, 0])
while todo:
	(node, parent) = todo.popleft()
	root_to_leaf.append(node)
	parents[node] = parent
	for to in edges[node]:
		if to == parent:
			continue
		todo.append([to, node])
size_of_subtree = [0] * n
pattern_in_subtree = [1] * n
for node in root_to_leaf[::-1]:
	parent = parents[node]
	size_of_subtree[node] += 1
	size_of_subtree[parent] += size_of_subtree[node]
	pattern_in_subtree[parent] *= nCr(size_of_subtree[parent], size_of_subtree[node]) * pattern_in_subtree[node] % mod
	pattern_in_subtree[parent] %= mod
answers = [0] * n
answers[0] = pattern_in_subtree[0]
for node in root_to_leaf:
	parent = parents[node]
	ans = answers[parent] * size_of_subtree[node] * inv[n - size_of_subtree[node]] % mod
	answers[node] = ans
for ans in answers:
	print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
mod = 10 ** 9 + 7
fact = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, 2 * 10 ** 5 + 5):
	fact.append(fact[-1] * i % mod)
	inv.append(inv[mod % i] * (mod - mod // i) % mod)
	finv.append(finv[-1] * inv[-1] % mod)

def nCr(n, r, mod):
	return fact[n] * finv[r] % mod * finv[n - r] % mod
n = int(input())
e = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	e[a - 1].append(b - 1)
	e[b - 1].append(a - 1)
numl = [0] * n
resl = [0] * n

def dfs(x, pre):
	num = 0
	res = 1
	for nex in e[x]:
		if nex == pre:
			continue
		dfs(nex, x)
		num += numl[nex]
		res *= nCr(num, numl[nex], mod) * resl[nex]
		res %= mod
	numl[x] = num + 1
	resl[x] = res
	return
dfs(0, -1)
ans = [0] * n
ans[0] = resl[0]

def dfs2(x, pre):
	for nex in e[x]:
		if nex == pre:
			continue
		pres = [resl[x], numl[x], resl[nex], numl[nex]]
		resl[x] *= pow(nCr(numl[x] - 1, numl[nex], mod) * resl[nex], mod - 2, mod)
		resl[x] %= mod
		numl[x] -= numl[nex]
		resl[nex] *= nCr(numl[x] + numl[nex] - 1, numl[x], mod) * resl[x]
		resl[nex] %= mod
		numl[nex] += numl[x]
		ans[nex] = resl[nex]
		dfs2(nex, x)
		(resl[x], numl[x], resl[nex], numl[nex]) = pres
	return
dfs2(0, -1)
for i in ans:
	print(i)


import sys
sys.setrecursionlimit(10 ** 7)
input = lambda : sys.stdin.readline().rstrip()
MOD = 10 ** 9 + 7
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	g[a].append(b)
	g[b].append(a)
lim = 10 ** 5 * 2
fact = [1, 1] + [0] * (lim - 1)
fact_inv = [1, 1] + [0] * (lim - 1)
inv = [0, 1] + [0] * (lim - 1)
for i in range(2, lim + 1):
	fact[i] = fact[i - 1] * i % MOD
	inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
	fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD

def comb(n, m):
	if n < m or n < 0 or m < 0:
		return 0
	return fact[n] * (fact_inv[m] * fact_inv[n - m] % MOD) % MOD

def icomb(n, m):
	if n < m or n < 0 or m < 0:
		return 0
	return fact_inv[n] * (fact[m] * fact[n - m] % MOD) % MOD
dp = [1] * n
size = [0] * n

def dfs(v, pv):
	for nv in g[v]:
		if nv == pv:
			continue
		dfs(nv, v)
		ns = size[nv] + 1
		size[v] += ns
		dp[v] *= dp[nv] * comb(size[v], ns) % MOD
		dp[v] %= MOD

def dfs2(v, pv):
	for nv in g[v]:
		if nv == pv:
			continue
		(d, sz) = (dp[v], size[v])
		d *= pow(dp[nv], MOD - 2, MOD) * icomb(sz, size[nv] + 1) % MOD
		d %= MOD
		sz -= size[nv] + 1
		size[nv] += sz + 1
		dp[nv] *= d * comb(size[nv], sz + 1) % MOD
		dp[nv] %= MOD
		dfs2(nv, v)
dfs(0, -1)
dfs2(0, -1)
print(*dp, sep='\n')


MOD = 10 ** 9 + 7
inv = [None, 1]
for i in range(2, 10 ** 5 * 2 + 1):
	inv.append(MOD - MOD // i * inv[MOD % i] % MOD)
fact = [1]
ifact = [1]
for i in range(1, 10 ** 5 * 2 + 1):
	fact.append(i * fact[-1] % MOD)
	ifact.append(inv[i] * ifact[-1] % MOD)

class Node:

	def __init__(self, ind):
		self.ind = ind
		self.val = 1
		self.ndesc = 1
		self.neighs = []
N = int(input())
nodes = [Node(i) for i in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	nodes[a - 1].neighs.append(nodes[b - 1])
	nodes[b - 1].neighs.append(nodes[a - 1])
stack = [(-1, nodes[0])]
for i in range(N):
	(fro, node) = stack[i]
	for neigh in node.neighs:
		if neigh.ind == fro:
			continue
		stack.append((node.ind, neigh))
for i in range(N - 1, -1, -1):
	(fro, node) = stack[i]
	node.val = node.val * fact[node.ndesc - 1] % MOD
	if fro == -1:
		continue
	nodes[fro].ndesc += node.ndesc
	nodes[fro].val = nodes[fro].val * node.val * ifact[node.ndesc] % MOD
stack = [(-1, node, nodes[0].val * inv[N] % MOD)]
for i in range(N):
	(fro, node, val) = stack[i]
	node.val = val * node.ndesc * inv[max(1, N - node.ndesc)] % MOD
	for neigh in node.neighs:
		if neigh.ind == fro:
			continue
		stack.append((node.ind, neigh, node.val))
for i in range(N):
	print(nodes[i].val)


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
sys.setrecursionlimit(100005)
mod = 1000000007
N = int(2 * 100000.0 + 100)
sz = [0] * N
dp = [0] * N
gr = defaultdict(list)

def modPow(a, b):
	ans = 1
	while b:
		if b & 1:
			ans = ans * a % mod
		b >>= 1
		a = a * a % mod
	return ans

def modInv(x):
	return modPow(x, mod - 2)

def dfs(x, par):
	sz[x] = 1
	for item in gr[x]:
		if item == par:
			continue
		dfs(item, x)
		sz[x] += sz[item]

def dfs1(x, par):
	for item in gr[x]:
		if item == par:
			continue
		dp[item] = dp[x] * (n - sz[item]) % mod
		dp[item] = dp[item] * modInv(sz[item]) % mod
		dfs1(item, x)
n = int(input())
for i in range(n - 1):
	(x, y) = mapi()
	gr[x].append(y)
	gr[y].append(x)
dfs(1, 0)
dp[1] = 1
for i in range(1, n + 1):
	dp[1] = dp[1] * sz[i] % mod
dfs1(1, 0)
res = 1
for i in range(1, n + 1):
	res = res * i % mod
for i in range(1, n + 1):
	dp[i] = res * modInv(dp[i]) % mod
for i in range(1, n + 1):
	print(dp[i])


import sys
input = sys.stdin.readline
from collections import deque
nn = 202020
mod = 10 ** 9 + 7
fa = [1] * (nn + 1)
fainv = [1] * (nn + 1)
for i in range(nn):
	fa[i + 1] = fa[i] * (i + 1) % mod
fainv[-1] = pow(fa[-1], mod - 2, mod)
for i in range(nn)[::-1]:
	fainv[i] = fainv[i + 1] * (i + 1) % mod
C = lambda a, b: fa[a] * fainv[b] * fainv[a - b] % mod if 0 <= b <= a else 0
N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
	(x, y) = map(int, input().split())
	X[x - 1].append(y - 1)
	X[y - 1].append(x - 1)
P = [-1] * N
Q = deque([0])
R = []
while Q:
	i = deque.popleft(Q)
	R.append(i)
	for a in X[i]:
		if a != P[i]:
			P[a] = i
			X[a].remove(i)
			deque.append(Q, a)
BU = [1] * N
TD = [1] * N
SI = [1] * N
for i in R[::-1]:
	a = 1
	s = 0
	for j in X[i]:
		a = a * BU[j] * fainv[SI[j]] % mod
		s += SI[j]
	SI[i] = s + 1
	BU[i] = fa[s] * a % mod
for i in R:
	a = TD[i] * fainv[N - SI[i]]
	for j in X[i]:
		a = a * BU[j] * fainv[SI[j]] % mod
	for j in X[i]:
		TD[j] = a * pow(BU[j], mod - 2, mod) % mod * fa[SI[j]] % mod * fa[N - 1 - SI[j]] % mod
for i in range(N):
	print(BU[i] * TD[i] % mod * C(N - 1, SI[i] - 1) % mod)