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*.
import sys
from collections import Counter

import functools
import math
import random
import sys
import os
from bisect import bisect_left,bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from heapq import nsmallest, nlargest, heapify, heappop, heappush
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# RSI = lambda: int(sys.stdin.buffer.readline())
RI = lambda: list(map(int, sys.stdin.buffer.readline().strip().split()))
RS = lambda: sys.stdin.buffer.readline().strip().decode('ascii')
RLS = lambda: sys.stdin.buffer.readline().strip().decode('ascii').split()
DEBUG = lambda *x: sys.stderr.write(f'{str(x)}\n')
# print = lambda d: sys.stdout.write(str(d) + "\n")

if sys.hexversion == 50924784:
    sys.stdin = open('./data')
"""
参考样例
输入
3
1 1
输出
4 3 3

输入
5
1 2 3 4
输出
5 8 9 8 5
题意简述：
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)。

思路：



"""
M = int(1e9) + 7

def solve():
    n, = RI()
    p = [0] + RI()
    ch = [[] for _ in range(n)]
    for i in range(n):
        p[i] -= 1
        if i:
            ch[p[i]].append(i)
    res = [-1] * (n + 1)
    sta = [0]
    while sta:
        for ne in ch[sta[-1]]:
            sta.append(ne)
        if not ch[sta[-1]]:
            res[sta[-1]] = 1
            c = sta.pop()
            while sta and sta[-1] == p[c]:
                c = sta.pop()
                r = 1
                for ne in ch[c]:
                    r *= res[ne] + 1
                    r %= M
                res[c] = r
    ans = [0] * n
    ans[0] = res[0]
    dq = deque([(0, 0)])
    while dq:
        c, pc = dq.popleft()
        for ne in ch[c]:
            nep = res[c] * (pc + 1) * pow(res[ne] + 1, M - 2, M) % M
            ans[ne] = (ans[c] + res[ne] - nep) % M
            dq.append((ne, nep))
    print(*ans)


    return 0

# for t in range(RI()[0] - 1):
#     solve()
solve()