#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
long long n;
long long Dp[200005], Ans[200005];
long long pre[200005], suf[200005], t[200005];
long long p[200005];
vector<long long> G[200005];
void Dfs(long long u) {
  long long len = G[u].size();
  for (long long i = 0; i < len; i++) {
    long long v = G[u][i];
    Dfs(v);
    Dp[u] *= (Dp[v] + 1);
    Dp[u] %= Mod;
  }
  if (len) {
    pre[G[u][0]] = suf[G[u][len - 1]] = 1;
    for (long long i = 1; i < len; i++) {
      pre[G[u][i]] = pre[G[u][i - 1]] * (1 + Dp[G[u][i - 1]]) % Mod;
    }
    for (long long i = len - 2; i >= 0; i--) {
      suf[G[u][i]] = suf[G[u][i + 1]] * (1 + Dp[G[u][i + 1]]) % Mod;
    }
  }
}
void Dfs2(long long u) {
  if (u == 1) {
    Ans[1] = Dp[1];
  } else
    Ans[u] = Dp[u] * (t[p[u]] + 1) % Mod;
  for (long long i = 0; i < G[u].size(); i++) {
    long long v = G[u][i];
    t[u] = pre[v] * suf[v] % Mod * (t[p[u]] + 1) % Mod;
    Dfs2(v);
  }
}
void Solve() {
  Dfs(1);
  Dfs2(1);
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) Dp[i] = 1;
  for (long long i = 2; i <= n; i++) {
    cin >> p[i];
    G[p[i]].push_back(i);
  }
  Solve();
  for (long long i = 1; i <= n; i++) cout << Ans[i] << " ";
  cout << endl;
  return 0;
}
