#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, dp[200200], up[200200], pr[200200];
vector<int> g[200200];
int pref[200200], suff[200200], two[200200], up2[200200];
int binpow(int a, int k) {
  a %= mod;
  if (k == 0) {
    if (a == 0) return 0;
    return 1;
  }
  int ans = binpow(a, k / 2);
  ans = 1ll * ans * ans % mod;
  if (k % 2) ans = 1ll * ans * a % mod;
  return ans;
}
void dfs1(int v) {
  int par = pr[v];
  dp[v] = 1;
  for (__typeof(g[v].begin()) it = g[v].begin(); it != g[v].end(); it++) {
    int to = *it;
    if (to != par) {
      dfs1(to);
      dp[v] = 1ll * dp[v] * (1 + dp[to]) % mod;
    }
  }
}
void precalc(int v) {
  int sz = (int)g[v].size();
  if (sz == 0) return;
  int cur = 1;
  for (int i = 0; i < sz; i++) {
    int to = g[v][i];
    cur = 1ll * cur * (1 + dp[to]) % mod;
    pref[to] = cur;
  }
  cur = 1;
  for (int i = sz - 1; i >= 0; i--) {
    int to = g[v][i];
    cur = 1ll * cur * (1 + dp[to]) % mod;
    suff[to] = cur;
  }
  for (int i = 0; i < sz; i++) {
    int to = g[v][i];
    int ans = 1;
    if (i) ans = 1ll * ans * pref[g[v][i - 1]] % mod;
    if (i + 1 < sz) ans = 1ll * ans * suff[g[v][i + 1]] % mod;
    up2[to] = ans;
  }
}
void dfs2(int v) {
  int par = pr[v];
  if (par == -1)
    up[v] = 0;
  else {
    up[v] = up2[v] * 1ll * (1 + up[par]) % mod;
  }
  for (__typeof(g[v].begin()) it = g[v].begin(); it != g[v].end(); it++) {
    int to = *it;
    if (to != par) dfs2(to);
  }
}
int main() {
  memset(pr, -1, sizeof pr);
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x;
    scanf("%d", &x);
    x--;
    pr[i] = x;
    g[x].push_back(i);
  }
  dfs1(0);
  for (int i = 0; i < n; i++) {
    precalc(i);
  }
  dfs2(0);
  for (int i = 0; i < n; i++) {
    if (i) printf(" ");
    int ans = dp[i] * 1ll * (up[i] + 1) % mod;
    printf("%d", ans);
  }
  printf("\n");
  return 0;
}
