#include <bits/stdc++.h>
using namespace std;
int n, p;
long long dp[200010];
long long ans[200010];
vector<int> e[200010];
void dfs1(int u, int fa) {
  dp[u] = 1;
  int len = e[u].size();
  for (int i = 0; i < len; i++) {
    int v = e[u][i];
    if (v == fa) continue;
    dfs1(v, u);
    dp[u] = (dp[u] * (dp[v] + 1)) % 1000000007;
  }
}
long long L[200010], R[200010];
void dfs2(int u, int fa) {
  int len = e[u].size();
  L[0] = 1, R[len - 1] = ans[u];
  for (int i = 1; i < len; i++)
    L[i] = L[i - 1] * (dp[e[u][i - 1]] + 1) % 1000000007;
  for (int i = len - 2; i >= 0; i--)
    R[i] = R[i + 1] * (dp[e[u][i + 1]] + 1) % 1000000007;
  for (int i = 0; i < len; i++) {
    int v = e[u][i];
    if (v == fa) continue;
    ans[v] = (L[i] * R[i] + 1) % 1000000007;
  }
  for (int i = 0; i < len; i++)
    if (e[u][i] != fa) dfs2(e[u][i], u);
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &p);
    e[p].push_back(i);
  }
  dfs1(1, 0);
  ans[1] = 1;
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) cout << ans[i] * dp[i] % 1000000007 << " ";
  cout << endl;
  return 0;
}
