#include <bits/stdc++.h>
int dp[200005], fa[200005], cnt = 0, n, ans[200005];
int pre[200005], suf[200005], last[200005], nxt[200005], ch[200005];
std::vector<int> G[200005];
void dfs(int now) {
  dp[now] = 1;
  int la = 0;
  for (int i = 0; i < G[now].size(); ++i) {
    dfs(G[now][i]);
    dp[now] = 1LL * dp[now] * (dp[G[now][i]] + 1) % 1000000007;
    pre[G[now][i]] = 1LL * pre[la] * (dp[G[now][i]] + 1) % 1000000007;
    last[G[now][i]] = la;
    la = G[now][i];
  }
  la = 0;
  for (int i = G[now].size() - 1; ~i; --i) {
    suf[G[now][i]] = 1LL * suf[la] * (dp[G[now][i]] + 1) % 1000000007;
    nxt[G[now][i]] = la;
    la = G[now][i];
  }
}
void dfs2(int now) {
  if (fa[now]) {
    int xx = pre[last[now]] * 1LL * suf[nxt[now]] % 1000000007 * ch[fa[now]] %
             1000000007;
    ch[now] = xx + 1;
    dp[now] = 1LL * dp[now] * (xx + 1) % 1000000007;
  }
  ans[now] = dp[now];
  for (int i = 0; i < G[now].size(); ++i) dfs2(G[now][i]);
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    scanf("%d", fa + i);
    G[fa[i]].push_back(i);
  }
  *pre = *suf = ch[1] = 1;
  dfs(1);
  dfs2(1);
  for (int i = 1; i <= n; ++i) printf("%d%c", ans[i], " \n"[i == n]);
  return 0;
}
