#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
int add(int a, int b) {
  if ((a += b) >= P) a -= P;
  return a;
}
int sub(int a, int b) {
  if ((a -= b) < 0) a += P;
  return a;
}
int mul(int a, int b) { return 1ll * a * b % P; }
int kpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a)) {
    if (b & 1) r = mul(r, a);
  }
  return r;
}
const int N = 2e5 + 6;
int u, f[N], ans[N], v, n;
vector<int> g[N], l[N], r[N];
void dfs(int u, int fa) {
  f[u] = 1;
  l[u].push_back(1);
  for (auto v : g[u]) {
    dfs(v, u);
    f[u] = mul(f[u], f[v] + 1);
    l[u].push_back(f[u]);
  }
  r[u].push_back(1);
  for (int i = ((int)g[u].size()) - 1; i >= (0); i--) {
    v = g[u][i];
    r[u].push_back(mul(r[u].back(), f[v] + 1));
  }
  reverse(r[u].begin(), r[u].end());
}
void dfs2(int u, int fa, int now) {
  for (int i = (0); i < ((int)g[u].size()); i++) {
    v = g[u][i];
    ans[v] = mul(f[v], mul(mul(now, l[u][i]), r[u][i + 1]) + 1);
    dfs2(v, u, mul(mul(now, l[u][i]), r[u][i + 1]) + 1);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> n;
  for (int i = (2); i < (n + 1); i++) {
    cin >> u;
    g[u].push_back(i);
  }
  dfs(1, 0);
  dfs2(1, 0, 1);
  ans[1] = f[1];
  for (int i = (1); i < (n + 1); i++) cout << ans[i] << " ";
  return 0;
}
