#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
const int inf = INT_MAX / 2;
const long long infl = 1LL << 60;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <int MOD>
struct ModInt {
  static const int Mod = MOD;
  unsigned x;
  ModInt() : x(0) {}
  ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
  ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
  int get() const { return (int)x; }
  ModInt &operator+=(ModInt that) {
    if ((x += that.x) >= MOD) x -= MOD;
    return *this;
  }
  ModInt &operator-=(ModInt that) {
    if ((x += MOD - that.x) >= MOD) x -= MOD;
    return *this;
  }
  ModInt &operator*=(ModInt that) {
    x = (unsigned long long)x * that.x % MOD;
    return *this;
  }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
  ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
  ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
  ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      std::swap(a, b);
      u -= t * v;
      std::swap(u, v);
    }
    return ModInt(u);
  }
  bool operator==(ModInt that) const { return x == that.x; }
  bool operator!=(ModInt that) const { return x != that.x; }
  ModInt operator-() const {
    ModInt t;
    t.x = x == 0 ? 0 : Mod - x;
    return t;
  }
};
template <int MOD>
ostream &operator<<(ostream &st, const ModInt<MOD> a) {
  st << a.get();
  return st;
};
template <int MOD>
ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
  ModInt<MOD> r = 1;
  while (k) {
    if (k & 1) r *= a;
    a *= a;
    k >>= 1;
  }
  return r;
}
ModInt<1000000007> dp[201010];
int N;
vector<int> E[201010];
int sz[201010];
void dfs(int cu, int pa = -1) {
  dp[cu] = 1;
  for (auto &to : E[cu])
    if (to != pa) {
      dfs(to, cu);
      dp[cu] *= dp[to] + 1;
    }
}
ModInt<1000000007> ans[201010];
void dfs2(int cu, int pa = -1) {
  ans[cu] = 1;
  for (auto &to : E[cu]) ans[cu] *= dp[to] + 1;
  vector<int> v;
  for (auto &to : E[cu]) v.push_back(to);
  int n = v.size();
  vector<ModInt<1000000007> > pre(n, 1), pos(n, 1);
  pre[0] = dp[v[0]] + 1;
  for (int i = 1; i < n; i++) pre[i] = pre[i - 1] * (dp[v[i]] + 1);
  pos[n - 1] = dp[v[n - 1]] + 1;
  for (int i = n - 2; i >= 0; i--) pos[i] = pos[i + 1] * (dp[v[i]] + 1);
  for (int i = 0; i < n; i++)
    if (v[i] != pa) {
      ModInt<1000000007> sm = 1;
      if (i) sm = pre[i - 1];
      if (i != n - 1) sm *= pos[i + 1];
      dp[cu] = sm;
      dfs2(v[i], cu);
    }
}
void _main() {
  cin >> N;
  for (int i = 1; i < N; i++) {
    int p;
    cin >> p;
    p--;
    E[p].push_back(i);
    E[i].push_back(p);
  }
  dfs(0);
  dfs2(0);
  for (int i = 0; i < N; i++) {
    if (i) printf(" ");
    printf("%d", ans[i].get());
  }
  printf("\n");
}
