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 Kotlin (1.0.0) (judge verdict: Accepted)

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val edges = Array(n) { mutableListOf<Int>() }
        for (i in 0 until n - 1) {
            val a = sc.nextInt() - 1
            val b = sc.nextInt() - 1
            edges[a].add(b)
            edges[b].add(a)
        }
        val fact = Array(200001) { ModInt(1) }
        for (i in 1..200000) {
            fact[i] = fact[i - 1] * i
        }
        // 0　根　iが根の部分木　サイズ
        val size = Array(n) { -1 }
        val memo = Array(n) { ModInt(1) }

        fun dfs1(pos: Int, p: Int) {
            var s = 0
            for (i in edges[pos].indices) {
                val to = edges[pos][i]
                if (to == p) continue
                dfs1(to, pos)
                s += size[to]
                memo[pos] *= memo[to]
                memo[pos] *= fact[size[to]].inverse()
            }
            memo[pos] *= fact[s]
            size[pos] = s + 1
        }

        dfs1(0, -1)
        // println(memo.joinToString(" "))
        // println(size.joinToString(" "))
        val ans = Array(n) { ModInt(1) }


        fun dfs2(pos: Int, p: Int, pp: ModInt) {
            // println("$pos $p $pp")
            ans[pos] = memo[pos] * (fact[size[pos] - 1] * fact[n - size[pos]]).inverse() * pp * fact[n - 1]
            for (i in edges[pos].indices) {
                val to = edges[pos][i]
                if (to == p) continue
                val nextPP = ans[pos] * (fact[n - 1] * memo[to]).inverse() * fact[size[to]] * fact[n - size[to] - 1]
                dfs2(to, pos, nextPP)
            }
        }
        dfs2(0, -1, ModInt(1))
        println(ans.joinToString("\n"))
    }
}

class ModInt(_num: Number) : Number() {
    companion object {
        const val mod: Long = 1000000007L
    }

    private val num: Long = if (_num.toLong() < 0) (_num.toLong() % mod) + mod else _num.toLong() % mod
    operator fun plus(right: Number) = ModInt(num + (right.toLong() % mod))
    operator fun minus(right: Number) = ModInt(num - (right.toLong() % mod))
    operator fun times(right: Number) = ModInt(num * (right.toLong() % mod))

    // modが素数の時のみ
    operator fun div(right: Number) = this * ModInt(right).inverse()

    fun power(n: Number): ModInt {
        var a = this
        var result = ModInt(1)
        var tmp = n.toLong()
        while (tmp > 0) {
            if (tmp % 2 == 1L) {
                result *= a
            }
            tmp /= 2
            a *= a
        }
        return result
    }

    // modが素数のときのみ 逆元
    fun inverse(): ModInt {
        return power(mod - 2L)
    }

    override fun toString() = num.toString()
    override fun toInt() = num.toInt()
    override fun toLong() = num
    override fun toByte() = num.toByte()
    override fun toChar() = num.toChar()
    override fun toDouble() = num.toDouble()
    override fun toFloat() = num.toFloat()
    override fun toShort() = num.toShort()
}


class MyScanner() {
    private var index = 0
    private var line = listOf<String>()

    fun next(): String {
        while (line.size <= index) {
            line = readLine()!!.split(' ')
            index = 0
        }
        return line[index++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun strList(): List<String> {
        index = line.size
        return readLine()!!.split(' ')
    }

    fun intList() = strList().map { it.toInt() }
    fun longList() = strList().map { it.toLong() }
    fun doubleList() = strList().map { it.toDouble() }
}