#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const long long maxn = 2e5 + 50, N = 2e6 + 10, SQRT = 300, base = 607583,
                mod = 1e9 + 7, INF = 1e18 + 1, lg = 25;
const long double eps = 1e-4;
long long n, par[maxn], down[maxn], up[maxn];
vector<long long> pre_down[maxn], suff_down[maxn];
vector<long long> edges[maxn];
void dfs_down(long long v) {
  down[v] = 1;
  pre_down[v].push_back(1), suff_down[v].push_back(1);
  for (auto u : edges[v]) {
    if (u != par[v]) {
      dfs_down(u);
      down[v] = (down[v] * (down[u] + 1)) % mod;
      pre_down[v].push_back(down[v]);
    }
  }
  for (long long i = (long long)edges[v].size() - 1; i >= 0; --i) {
    long long u = edges[v][i];
    if (u != par[v]) {
      suff_down[v].push_back((suff_down[v].back() * (down[u] + 1)) % mod);
    }
  }
  reverse(suff_down[v].begin(), suff_down[v].end());
}
void dfs_up(long long v, long long idx) {
  up[v] = 1;
  if (par[v] != -1) {
    up[v] = up[par[v]];
    up[v] =
        (((pre_down[par[v]][idx] * suff_down[par[v]][idx + 1]) % mod) * up[v] +
         1) %
        mod;
  }
  long long id = 0;
  for (auto u : edges[v]) {
    if (u != par[v]) {
      dfs_up(u, id);
      id++;
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  par[0] = -1;
  for (long long i = 1; i < n; ++i) {
    cin >> par[i];
    par[i]--;
    edges[par[i]].push_back(i);
    edges[i].push_back(par[i]);
  }
  dfs_down(0);
  dfs_up(0, -1);
  for (long long i = 0; i < n; ++i) {
    cout << (down[i] * up[i]) % mod << ' ';
  }
  cout << '\n';
}
