#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;
long long n, dp[N], sol[N];
vector<long long> adj[N], prefix[N], suffix[N];
void dfs(int node, int parent) {
  prefix[node].resize(adj[node].size());
  suffix[node].resize(adj[node].size());
  long long cur = 1;
  for (int i = 0; i < adj[node].size(); ++i) {
    int child = adj[node][i];
    if (child != parent) {
      dfs(child, node);
      (cur *= (1 + dp[child])) %= mod;
    }
    prefix[node][i] = cur;
  }
  cur = 1;
  for (int i = adj[node].size() - 1; i >= 0; --i) {
    int child = adj[node][i];
    if (child != parent) (cur *= (1 + dp[child])) %= mod;
    suffix[node][i] = cur;
  }
  dp[node] = cur;
}
void solve(int node, int parent) {
  sol[node] = dp[node];
  for (int i = 0; i < adj[node].size(); ++i) {
    int child = adj[node][i];
    if (child == parent) continue;
    long long node_dp = dp[node], child_dp = dp[child];
    dp[node] = (i ? prefix[node][i - 1] : 1);
    (dp[node] *= (i + 1 < adj[node].size() ? suffix[node][i + 1] : 1)) %= mod;
    (dp[node] *= (1 + dp[parent])) %= mod;
    (dp[child] *= (1 + dp[node])) %= mod;
    solve(child, node);
    dp[node] = node_dp, dp[child] = child_dp;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    int x;
    cin >> x;
    adj[i].push_back(x);
    adj[x].push_back(i);
  }
  dfs(1, 0);
  solve(1, 0);
  for (int i = 1; i <= n; ++i) cout << sol[i] << ' ';
  return 0;
}
