#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
long long MOD = 1e9 + 7;
long long power(long long x, int p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = (r * x) % MOD;
    p >>= 1;
    x = (x * x) % MOD;
  }
  return (r + MOD) % MOD;
}
long long dfs(const vector<vector<int> >& E, vector<long long>& first, int u,
              int p) {
  long long c = 1;
  for (auto v : E[u])
    if (v != p) c = (c * dfs(E, first, v, u)) % MOD;
  first[u] = (c + (u != p)) % MOD;
  return first[u];
}
vector<long long> ans, skip;
void dfs_spread(const vector<vector<int> >& E, vector<long long>& first,
                vector<int>& p, int u) {
  ans[u] = (first[u] + MOD) % MOD;
  if (first[u] == 0) {
    long long c = 1;
    int z = 0;
    while (first[E[u][z]]) c = (c * first[E[u][z++]]) % MOD;
    for (int h = z + 1; h < (int)E[u].size(); ++h)
      c = (c * first[E[u][h]]) % MOD;
    skip[E[u][z]] = c;
    for (auto v : E[u])
      if (v != E[u][z]) skip[v] = 0;
  } else
    for (auto v : E[u]) skip[v] = (first[u] * power(first[v], MOD - 2)) % MOD;
  for (auto v : E[u])
    if (v != p[u]) {
      long long prev = first[v];
      p[v] = u;
      first[u] = (skip[v] + 1) % MOD;
      first[v] = ((first[v] - 1) * first[u]) % MOD;
      dfs_spread(E, first, p, v);
      first[v] = prev;
      first[u] = ans[u];
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int> > E(n);
  for (int u = 1; u < n; ++u) {
    int v;
    cin >> v;
    --v;
    E[u].push_back(v), E[v].push_back(u);
  }
  vector<long long> first(n, -1);
  vector<int> p(n, 0);
  ans.assign(n, -1), skip.assign(n, -1);
  first[0] = dfs(E, first, 0, 0);
  dfs_spread(E, first, p, 0);
  for (auto x : ans) cout << x << " ";
  cout << '\n';
  exit(0);
}
