#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979323846;
const int inf = (int)1e9;
const long double eps = 1e-9;
const int N = (int)2e5 + 5;
const int mod = inf + 7;
int n;
vector<int> g[N];
long long int dp[N];
long long int res[N];
void go(int v, int pr = -1) {
  dp[v] = 1;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to == pr) {
      continue;
    }
    go(to, v);
    dp[v] *= (dp[to] + 1);
    dp[v] %= mod;
  }
}
void solve(int v, int pr = -1) {
  int sz = g[v].size();
  dp[v] = 1;
  vector<long long int> l(sz);
  vector<long long int> r(sz);
  for (int i = 0; i < sz; ++i) {
    int j = sz - i - 1;
    l[i] = dp[g[v][i]] + 1;
    r[j] = dp[g[v][j]] + 1;
    if (i) {
      l[i] *= l[i - 1];
      r[j] *= r[j + 1];
    }
    l[i] %= mod;
    r[j] %= mod;
    int to = g[v][i];
    dp[v] = ((dp[to] + 1) * dp[v]) % mod;
  }
  res[v] = dp[v];
  for (int i = 0; i < sz; ++i) {
    int to = g[v][i];
    if (to == pr) {
      continue;
    }
    dp[v] = 1;
    if (i) {
      dp[v] *= l[i - 1];
    }
    if (i + 1 < sz) {
      dp[v] *= r[i + 1];
    }
    dp[v] %= mod;
    solve(to, v);
    dp[v] = res[v];
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x;
    scanf("%d", &x);
    --x;
    g[x].push_back(i);
    g[i].push_back(x);
  }
  go(0);
  solve(0);
  for (int i = 0; i < n; ++i) {
    cout << res[i] << " ";
  }
  return 0;
}
