#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
;
const long long mod = 1e9 + 7;
const int maxn = 2 * 1e5 + 5;
int n;
vector<vector<int> > g;
vector<long long> ans;
vector<long long> dp;
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> n;
  g.resize(n);
  dp.resize(n, 1);
  ans.resize(n);
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    a--;
    g[a].push_back(i);
    g[i].push_back(a);
  }
}
vector<long long> prefs[maxn];
vector<long long> sufs[maxn];
void calcDP(int v, int p = -1) {
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    calcDP(to, v);
    dp[v] *= (dp[to] + 1ll);
    dp[v] %= mod;
    prefs[v].push_back(dp[v]);
  }
  dp[v] = 1;
  for (int i = g[v].size() - 1; i >= 0; i--) {
    int to = g[v][i];
    if (to == p) continue;
    dp[v] *= (dp[to] + 1ll);
    dp[v] %= mod;
    sufs[v].push_back(dp[v]);
  }
  dp[v] %= mod;
  reverse(sufs[v].begin(), sufs[v].end());
}
void going(int v, int p = -1, int upVal = 0) {
  ans[v] = dp[v];
  int j = 0;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    long long oldDpV = dp[v], oldDpTo = dp[to];
    long long newDpV = 1;
    if (j) {
      newDpV *= prefs[v][j - 1];
      newDpV %= mod;
    }
    if (j < (int)prefs[v].size() - 1) {
      newDpV *= sufs[v][j + 1];
      newDpV %= mod;
    }
    newDpV *= (upVal + 1ll);
    newDpV %= mod;
    long long newDpTo = dp[to] * (newDpV + 1ll);
    newDpTo %= mod;
    dp[v] = newDpV;
    dp[to] = newDpTo;
    going(to, v, dp[v]);
    dp[v] = oldDpV;
    dp[to] = oldDpTo;
    j++;
  }
}
void solve() {
  calcDP(0);
  going(0);
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
}
signed main() {
  init();
  solve();
  return 0;
}
