#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
int dp_down[maxn];
int dp_up[maxn];
int par[maxn];
vector<int> G[maxn];
bool vis_down[maxn];
bool vis_up[maxn];
void dfs_down(int v) {
  if (vis_down[v]) return;
  vis_down[v] = true;
  dp_down[v] = 1;
  for (int u : G[v]) {
    dfs_down(u);
    dp_down[v] = (1ll * dp_down[v] * (dp_down[u] + 1)) % mod;
  }
}
void dfs_up(int v) {
  if (vis_up[v]) return;
  vis_up[v] = true;
  int pi = 1;
  for (int u : G[v]) {
    dp_up[u] = (1ll * dp_up[u] * pi) % mod;
    pi = (1ll * pi * (dp_down[u] + 1)) % mod;
  }
  pi = 1;
  for (auto rit = G[v].rbegin(); rit != G[v].rend(); rit++) {
    int u = *rit;
    dp_up[u] = (1ll * dp_up[u] * pi) % mod;
    pi = (1ll * pi * (dp_down[u] + 1)) % mod;
  }
  for (int u : G[v]) {
    dp_up[u] = (1ll * dp_up[u] * dp_up[v] + 1) % mod;
    dfs_up(u);
  }
}
int main() {
  par[1] = 0;
  fill(dp_down, dp_down + maxn, 1);
  fill(dp_up, dp_up + maxn, 1);
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    par[i] = x;
    G[x].push_back(i);
  }
  dfs_down(1);
  dfs_up(1);
  for (int i = 1; i <= n; i++) {
    printf("%lld ", (1ll * dp_up[i] * dp_down[i]) % mod);
  }
  printf("\n");
  return 0;
}
