#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int64_t mod = 1000000007;
int n, p[N];
vector<vector<int>> G;
void input() {
  cin >> n;
  for (int i = int(0); i < int(n - 1); ++i) cin >> p[i], --p[i];
  G.assign(n, vector<int>());
  for (int i = int(0); i < int(n - 1); ++i) {
    G[p[i]].push_back(i + 1);
    G[i + 1].push_back(p[i]);
  }
}
int64_t dp[N];
void dfs(int v) {
  dp[v] = 1;
  for (int c : G[v]) {
    if (dp[c] >= 0) continue;
    dfs(c);
    dp[v] = dp[v] * (dp[c] + 2) % mod;
  }
  --dp[v];
}
int64_t ans[N];
void dfs1(int v, int64_t t) {
  ans[v] = (dp[v] + 1) * (t + 1) % mod;
  vector<int64_t> r;
  for (int c : G[v]) {
    if (ans[c] >= 0) continue;
    r.push_back(dp[c] + 2);
  }
  r.push_back(1);
  for (int i = r.size() - 2; i >= 0; --i) {
    r[i] = r[i] * r[i + 1] % mod;
  }
  int i = 0;
  int64_t l = 1;
  for (int c : G[v]) {
    if (ans[c] >= 0) continue;
    dfs1(c, l * r[i + 1] % mod * (t + 1) % mod);
    ++i, l = l * (dp[c] + 2) % mod;
  }
}
void solve() {
  fill_n(dp, n, -1);
  dfs(0);
  fill_n(ans, n, -1);
  dfs1(0, 0);
  for (int i = int(0); i < int(n - 1); ++i) cout << ans[i] << ' ';
  cout << ans[n - 1] << endl;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  input();
  solve();
}
