#include <bits/stdc++.h>
using namespace std;
template <class BidirIt>
BidirIt prev(BidirIt it,
             typename iterator_traits<BidirIt>::difference_type n = 1) {
  std::advance(it, -n);
  return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
               typename iterator_traits<ForwardIt>::difference_type n = 1) {
  std::advance(it, n);
  return it;
}
const double EPS = 1e-9;
const double PI = 3.141592653589793238462;
template <typename T>
inline T sq(T a) {
  return a * a;
}
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
int par[MAXN];
vector<int> gr[MAXN], pref[MAXN], suff[MAXN];
int dp[MAXN], up[MAXN];
inline int mul_mod(int a, int b) { return (long long)a * b % mod; }
inline void add_mod(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mpow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = mul_mod(res, a);
    a = mul_mod(a, a);
    b >>= 1;
  }
  return res;
}
void dfs1(int u) {
  dp[u] = 1;
  if (gr[u].empty()) return;
  for (auto v : gr[u]) {
    dfs1(v);
    pref[u].push_back(mul_mod(pref[u].empty() ? 1 : pref[u].back(), dp[v] + 1));
  }
  dp[u] = pref[u].back();
  for (auto v = gr[u].rbegin(); v != gr[u].rend(); v++) {
    suff[u].push_back(
        mul_mod(suff[u].empty() ? 1 : suff[u].back(), dp[*v] + 1));
  }
  reverse((suff[u]).begin(), (suff[u]).end());
}
void dfs2(int u) {
  up[u] = 1;
  if (u != 1) {
    int pos = lower_bound((gr[par[u]]).begin(), (gr[par[u]]).end(), u) -
              gr[par[u]].begin();
    int s = (int)gr[par[u]].size() - 1;
    add_mod(up[u], mul_mod(up[par[u]],
                           mul_mod((pos == 0) ? 1 : pref[par[u]][pos - 1],
                                   (pos == s) ? 1 : suff[par[u]][pos + 1])));
  }
  for (auto v : gr[u]) dfs2(v);
}
int main() {
  int n;
  scanf("%d", &n);
  par[1] = -1;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &par[i]);
    gr[par[i]].push_back(i);
  }
  dfs1(1);
  dfs2(1);
  for (int i = 1; i <= n; i++) printf("%d ", mul_mod(dp[i], up[i]));
  puts("");
  return 0;
}
