#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
void add(int64_t& a, int64_t b) { a = (a + b) % MOD; }
void mul(int64_t& a, int64_t b) { a = a * b % MOD; }
int N;
vector<int> edges[200000];
int64_t ans[200000];
int64_t dp[200000][2];
void dfs(int i, int p) {
  dp[i][0] = dp[i][1] = 1;
  for (int j : edges[i]) {
    dfs(j, i);
    mul(dp[i][0], dp[j][0]);
    mul(dp[i][1], dp[j][0] + dp[j][1]);
  }
}
void dfs2(int i, int p, int64_t d0, int64_t d1) {
  ans[i] = dp[i][1] * d1 % MOD;
  int sz = edges[i].size();
  vector<int64_t> l0(sz + 2, 1), r0(sz + 2, 1), l1(sz + 2, 1), r1(sz + 2, 1);
  for (int idx = 0; idx < sz; idx++) {
    int j = edges[i][idx];
    l0[idx + 1] = l0[idx] * dp[j][0] % MOD;
    l1[idx + 1] = l1[idx] * (dp[j][0] + dp[j][1]) % MOD;
  }
  for (int idx = sz - 1; idx >= 0; idx--) {
    int j = edges[i][idx];
    r0[idx + 1] = r0[idx + 2] * dp[j][0] % MOD;
    r1[idx + 1] = r1[idx + 2] * (dp[j][0] + dp[j][1]) % MOD;
  }
  for (int idx = 0; idx < sz; idx++) {
    int64_t dd0 = l0[idx] * r0[idx + 2] % MOD * d0 % MOD;
    int64_t dd1 = l1[idx] * r1[idx + 2] % MOD * d1 % MOD;
    dfs2(edges[i][idx], i, dd0, (dd0 + dd1) % MOD);
  }
}
int main() {
  cin >> N;
  for (int i = 1; i < N; i++) {
    int p;
    cin >> p;
    edges[p - 1].push_back(i);
  }
  dfs(0, -1);
  dfs2(0, -1, 1, 1);
  for (int i = 0; i < N; i++) cout << ans[i] << " \n"[i == N - 1];
  return 0;
}
