The country has *n* cities and *n* - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to *n* inclusive.

All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that the citizens are happy about road improvement if the path from the capital located in city *x* to any other city contains at most one bad road.

Your task is — for every possible *x* determine the number of ways of improving the quality of some roads in order to meet the citizens' condition. As those values can be rather large, you need to print each value modulo 1 000 000 007 (10<sup class="upper-index">9</sup> + 7).
The first line of the input contains a single integer *n* (2 ≤ *n* ≤ 2·10<sup class="upper-index">5</sup>) — the number of cities in the country. Next line contains *n* - 1 positive integers *p*<sub class="lower-index">2</sub>, *p*<sub class="lower-index">3</sub>, *p*<sub class="lower-index">4</sub>, ..., *p*<sub class="lower-index">*n*</sub> (1 ≤ *p*<sub class="lower-index">*i*</sub> ≤ *i* - 1) — the description of the roads in the country. Number *p*<sub class="lower-index">*i*</sub> means that the country has a road connecting city *p*<sub class="lower-index">*i*</sub> and city *i*.
# Problem: D. Road Improvement
# Contest: Codeforces - Codeforces Round 302 (Div. 1)
# URL: https://codeforces.com/problemset/problem/543/D
# Memory Limit: 256 MB
# Time Limit: 2000 ms

import sys
import random
from types import GeneratorType
import bisect
import io, os
from bisect import *
from collections import *
from contextlib import redirect_stdout
from itertools import *
from array import *
from functools import lru_cache, reduce
from heapq import *
from math import sqrt, gcd, inf

if sys.version >= '3.8':  # ACW没有comb
    from math import comb

RI = lambda: map(int, sys.stdin.buffer.readline().split())
RS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())
RILST = lambda: list(RI())
DEBUG = lambda *x: sys.stderr.write(f'{str(x)}\n')
# print = lambda d: sys.stdout.write(str(d) + "\n")  # 打开可以快写，但是无法使用print(*ans,sep=' ')这种语法,需要print(' '.join(map(str, p)))，确实会快。

DIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)]  # 右下左上
DIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),
         (-1, 1)]  # →↘↓↙←↖↑↗
RANDOM = random.randrange(2 ** 62)
MOD = 10 ** 9 + 7
# MOD = 998244353
PROBLEM = """https://codeforces.com/problemset/problem/543/D

输入 n(2≤n≤2e5) 和 n-1 个数 p2,p3,...,pn，表示一棵 n 个节点的无根树，节点编号从 1 开始，i 与 pi(1≤pi≤i-1) 相连。
定义 a(x) 表示以 x 为根时的合法标记方案数，模 1e9+7。其中【合法标记】定义为：对树的某些边做标记，使得 x 到任意点的简单路径上，至多有一条边是被标记的。
输出 a(1),a(2),...,a(n)。
输入
3
1 1
输出
4 3 3

输入
5
1 2 3 4
输出
5 8 9 8 5
"""
"""换根 DP。不了解的同学请看右边的链接。

先来计算 a(1)，此时 1 为树根。
定义 f(i) 表示子树 i 的合法标记方案数。
对于 i 的儿子 j，考虑 i-j 这条边是否标记：
- 标记：那么子树 j 的所有边都不能标记，方案数为 1。
- 不标记：那么方案数就是 f(j)。
i 的每个儿子互相独立，所以根据乘法原理有 
f(i) = (f(j1)+1) * (f(j2)+1) * ... * (f(jm)+1)
其中 j1,j2,...,jm 是 i 的儿子。

然后来计算其余 a(i)。
考虑把根从 i 换到 j：
对于 j 来说，方案数需要在 f(j) 的基础上，再乘上【父亲 i】这棵子树的方案数，即 a(i) / (f(j)+1)。 
所以 a(j) = f(j) * (a(i)/(f(j)+1) + 1)

本题的一个易错点是，f(j)+1 可能等于 M=1e9+7，取模会变成 0，但是 0 没有逆元。
处理方式有很多，我的做法是定义二元组 (k,x) 表示 M^k * x % M，在这基础上定义：
- 乘法运算：(k1, x1) * (k2, x2) = (k1+k2, x1*x2%M)
- 除法运算：(k1, x1) / (k2, x2) = (k1-k2, x1*inv(x2)%M)  这里 k1>=k2
- 加一运算：请读者思考（需要分类讨论，具体见代码）

当 k>0 时，(k,x) 的实际值为 0；当 k=0 时，(k,x) 的实际值为 x。

https://codeforces.com/contest/543/submission/214621886"""


def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to

    return wrappedfunc


#       ms
def solve():
    n, = RI()
    a = RILST()
    g = [[] for _ in range(n)]
    for i, p in enumerate(a, start=1):
        g[i].append(p - 1)
        g[p - 1].append(i)

    down = [1] * n  # 每个节点向下子树至少画一下的方案数

    @bootstrap
    def dfs(u, fa):
        for v in g[u]:
            if v == fa: continue
            yield dfs(v, u)
            down[u] = down[u] * (1 + down[v]) % MOD
        yield

    dfs(0, -1)
    # print(g)
    ans = down[:]

    @bootstrap
    def reroot(u, fa):
        for v in g[u]:
            if v == fa: continue
            # ans[v] = (ans[u] // (down[v] + 1) + 1) * down[v]
            ans[v] = (ans[u] * pow(down[v] + 1, MOD - 2, MOD) + 1) * down[v]%MOD
            yield reroot(v, u)
        yield

    reroot(0, -1)

    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    t = 0
    if t:
        t, = RI()
        for _ in range(t):
            solve()
    else:
        solve()
