#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 9;
const long long MOD = 1e9 + 7;
long long dp[MAX], dp2[MAX];
vector<int> g[MAX];
void dfs1(int v) {
  dp[v] = 1;
  for (auto u : g[v]) {
    dfs1(u);
    dp[v] = dp[v] * (dp[u] + 1) % MOD;
  }
  return;
}
void dfs2(int v) {
  long long p1[g[v].size()];
  long long p2[g[v].size()];
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    p1[i] = ((i == 0) ? (dp[u] + 1) : p1[i - 1] * (dp[u] + 1) % MOD);
  }
  for (int i = g[v].size() - 1; i >= 0; i--) {
    int u = g[v][i];
    p2[i] =
        ((i == g[v].size() - 1) ? (dp[u] + 1) : p2[i + 1] * (dp[u] + 1) % MOD);
  }
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    long long m = ((i == g[v].size() - 1) ? 1 : p2[i + 1]) *
                  ((i == 0) ? 1 : p1[i - 1]) % MOD;
    m = m * dp2[v] % MOD;
    dp2[u] = m + 1;
    dfs2(u);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int p;
    cin >> p;
    p--;
    g[p].push_back(i + 1);
  }
  dp2[0] = 1;
  dfs1(0);
  dfs2(0);
  for (int i = 0; i < n; i++) {
    cout << dp[i] * max(dp2[i], (long long)1) % MOD << " ";
  }
  cout << "\n";
}
