from fractions import gcd

import sys

sys.setrecursionlimit(4100000)



def os(): return eval(input())

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

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

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

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

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

def mlas(L): return [eval(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)



#MOD

P = 10**9 + 7

N = 200001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心

inv = [0] + [1] # 1/x

finv = [1] + [1] # 1/x!

fac = [1] + [1] # x!

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 # error

    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



def step(x):

    return T(x.num, x.child+1)

def merge(x, y):

    if(x.num==-1): return y

    if(y.num==-1): return x

    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 = [T(-1, -1) for _ in range(200001)]

dat = [T(-1, -1) 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]))

    if(cnt==0): down_data[now] = T(1, 0)



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 = T(-1, -1) if cnt==0 else left[cnt-1]

        y = T(-1, -1) 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, T(1, 0))

    for i in range(1, n+1):

        print((dat[i].num))



if __name__ == "__main__": main()

from fractions import gcd

import sys

sys.setrecursionlimit(4100000)



def os(): return eval(input())

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

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

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

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

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

def mlas(L): return [eval(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)

#MOD

P = 10**9 + 7

N = 200001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心

inv = [0] + [1] # 1/x

finv = [1] + [1] # 1/x!

fac = [1] + [1] # x!

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 # error

    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P



#-------------------------------------------------------------------

#全方位木dpで扱うクラス

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):

    if(x.num==-1): return y

    if(y.num==-1): return x

    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))



if __name__ == "__main__": main()

from fractions import gcd
import sys

sys.setrecursionlimit(4100000)


def os():
    return eval(input())


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


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


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


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


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


def mlas(L):
    return [eval(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)


# MOD
P = 10**9 + 7
N = 200001  # 使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1]  # 1/x
finv = [1] + [1]  # 1/x!
fac = [1] + [1]  # x!
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  # error
    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


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


def merge(x, y):
    if x.num == -1:
        return y
    if y.num == -1:
        return x
    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 = [T(-1, -1) for _ in range(200001)]
dat = [T(-1, -1) 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]))
    if cnt == 0:
        down_data[now] = T(1, 0)


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 = T(-1, -1) if cnt == 0 else left[cnt - 1]
        y = T(-1, -1) 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, T(1, 0))
    for i in range(1, n + 1):
        print((dat[i].num))


if __name__ == "__main__":
    main()

from fractions import gcd
import sys

sys.setrecursionlimit(4100000)


def os():
    return eval(input())


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


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


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


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


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


def mlas(L):
    return [eval(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)


# MOD
P = 10**9 + 7
N = 200001  # 使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1]  # 1/x
finv = [1] + [1]  # 1/x!
fac = [1] + [1]  # x!
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  # error
    return (fac[a] * ((finv[b] * finv[a - b]) % P)) % P


# -------------------------------------------------------------------
# 全方位木dpで扱うクラス
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):
    if x.num == -1:
        return y
    if y.num == -1:
        return x
    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))


if __name__ == "__main__":
    main()

+# 全方位木dpで扱うクラス +# 零元 +zero = T(1, 0) +# 一個遷移した時の変化 +# マージ -down_data = [T(-1, -1) for _ in range(200001)] -dat = [T(-1, -1) for _ in range(200001)] +down_data = [zero for _ in range(200001)] +dat = [zero for _ in range(200001)] -    if cnt == 0: -        down_data[now] = T(1, 0) +    # 累積 -        x = T(-1, -1) if cnt == 0 else left[cnt - 1] -        y = T(-1, -1) if cnt == len(right) - 1 else right[len(right) - 2 - cnt] +        x = zero if cnt == 0 else left[cnt - 1] +        y = zero if cnt == len(right) - 1 else right[len(right) - 2 - cnt] -    dfs_rev(root, -1, T(1, 0)) +    dfs_rev(root, -1, zero)