Problem:
Score : 600 points

Problem Statement

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 1

3
1 2
1 3

Sample Output 1

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

Sample Input 2

2
1 2

Sample Output 2

1
1

The graph in this input is as follows:

Sample Input 3

5
1 2
2 3
3 4
3 5

Sample Output 3

2
8
12
3
3

The graph in this input is as follows:

Sample Input 4

8
1 2
2 3
3 4
3 5
3 6
6 7
6 8

Sample Output 4

40
280
840
120
120
504
72
72

The graph in this input is as follows:

Solution in LuaJIT (2.0.4) (judge verdict: Runtime Error)

local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end
local n = io.read("*n")

local fact = {1}
for i = 2, n do
  fact[i] = bmul(fact[i - 1], i)
end
local function getComb(n, k)
  if k == 0 or k == n then return 1 end
  return bmul(fact[n], modinv(bmul(fact[k], fact[n - k])))
end
local function getInvComb(n, k)
  if k == 0 or k == n then return 1 end
  return bmul(fact[k], bmul(fact[n - k], modinv(fact[n])))
end


local edge = {}
local parent = {}
local childcnt = {}
local child_asked_cnt = {}
for i = 1, n do
  edge[i] = {}
  parent[i] = 0
  childcnt[i] = 0
  child_asked_cnt[i] = 0
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  table.insert(edge[b], a)
end
local tasks = {1}
for itask = 1, n do
  local src = tasks[itask]
  for i = 1, #edge[src] do
    local dst = edge[src][i]
    if parent[src] ~= dst then
      parent[dst] = src
      table.insert(tasks, dst)
    end
  end
end
tasks = {}
-- find leaf
for i = 2, n do
  if #edge[i] == 1 then
    table.insert(tasks, i)
  end
end
for itask = 1, n - 1 do
  local child = tasks[itask]
  local p = parent[child]
  childcnt[p] = childcnt[p] + 1 + childcnt[child]
  child_asked_cnt[p] = child_asked_cnt[p] + 1
  if child_asked_cnt[p] + 1 == #edge[p] then
    table.insert(tasks, p)
  end
end
local allmult = 1
local multiple = {}
for i = 1, n do
  multiple[i] = 1
end
tasks = { {1, 1} }
for itask = 1, n do
  local src, mul = tasks[itask][1], tasks[itask][2]
  -- when start from parents
  multiple[src] = bmul(multiple[src], mul)
  local childall = childcnt[src]
  local otherall = n - 1
  local prog_mul = 1
  for i = 1, #edge[src] do
    local dst = edge[src][i]
    if parent[src] ~= dst then
      prog_mul = bmul(prog_mul, getComb(otherall, 1 + childcnt[dst]))
      otherall = otherall - 1 - childcnt[dst]
    end
  end
  -- when start from src
  multiple[src] = bmul(multiple[src], prog_mul)
  -- affect to parents
  local affect = bmul(prog_mul, getInvComb(n - 1, n - 1 - childcnt[src]))
  allmult = bmul(allmult, affect)
  -- print(src, prog_mul, allmult)
  mul = bmul(mul, modinv(affect))
  multiple[src] = bmul(multiple[src], modinv(affect))
  -- when start from children
  for i = 1, #edge[src] do
    local dst = edge[src][i]
    if parent[src] ~= dst then
      local prog = bmul(prog_mul, mul)
      prog = bmul(prog, getInvComb(n - 1, 1 + childcnt[dst]))
      table.insert(tasks, {dst, prog})
    end
  end
end
for i = 1, n do
  -- print(i, allmult, multiple[i])
  local z = bmul(allmult, multiple[i])
  print(z)
end