#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 200005;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  return x * f;
}
int n, m, mul_pre[N], mul_suc[N], dp1[N], dp2[N], cnt, head[N], u, top;
vector<int> g[N];
struct node {
  int to, next;
} num[2 * N];
void add(int x, int y) {
  num[++cnt].to = y;
  num[cnt].next = head[x];
  head[x] = cnt;
}
void dfs(int x, int fa) {
  dp1[x] = 1;
  for (int i = head[x]; i; i = num[i].next)
    if (num[i].to != fa) {
      dfs(num[i].to, x);
      dp1[x] = (long long)dp1[x] * (dp1[num[i].to] + 1) % mod;
      g[x].push_back(num[i].to);
    }
  top = g[x].size();
  if (top == 0) return;
  mul_pre[g[x][0]] = 1;
  mul_suc[g[x][top - 1]] = 1;
  for (int i = 1, j = top - 2; i < top; i++, j--) {
    mul_pre[g[x][i]] =
        (long long)mul_pre[g[x][i - 1]] * (dp1[g[x][i - 1]] + 1) % mod;
    mul_suc[g[x][j]] =
        (long long)mul_suc[g[x][j + 1]] * (dp1[g[x][j + 1]] + 1) % mod;
  }
}
void dfs2(int x, int fa) {
  for (int i = head[x]; i; i = num[i].next)
    if (num[i].to != fa) {
      dp2[num[i].to] = (long long)dp2[x] * mul_pre[num[i].to] % mod *
                           mul_suc[num[i].to] % mod +
                       1;
      dfs2(num[i].to, x);
    }
}
int main() {
  n = read();
  for (int i = 2; i <= n; i++) u = read(), add(u, i), add(i, u);
  dfs(1, -1);
  dp2[1] = 1;
  dfs2(1, -1);
  for (int i = 1; i <= n; i++) printf("%d ", (long long)dp1[i] * dp2[i] % mod);
  return 0;
}
