#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
int n;
long long dp[N], ans[N], fdp[N];
vector<int> edge[N];
vector<int> L[N], R[N];
long long fastPow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
void dfs(int u, int fa) {
  dp[u] = 1;
  long long pre = 1;
  L[u].resize(edge[u].size());
  R[u].resize(edge[u].size());
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    L[u][i] = pre;
    if (v == fa) continue;
    dfs(v, u);
    dp[u] = dp[u] * (dp[v] + 1) % mod;
    L[u][i] = L[u][i] * (dp[v] + 1) % mod;
    pre = L[u][i];
  }
  pre = 1;
  for (int i = edge[u].size() - 1; i >= 0; i--) {
    int v = edge[u][i];
    R[u][i] = pre;
    if (v == fa) continue;
    R[u][i] = R[u][i] * (dp[v] + 1) % mod;
    pre = R[u][i];
  }
}
void dfs3(int u, int fa, long long val) {
  ans[u] = dp[u] * (val + 1) % mod;
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (v == fa) continue;
    long long nxv = 1;
    if (i) nxv = L[u][i - 1];
    if (i + 1 < edge[u].size()) nxv = nxv * R[u][i + 1] % mod;
    dfs3(v, u, nxv * (val + 1) % mod);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    edge[i].push_back(x);
    edge[x].push_back(i);
  }
  dfs(1, 0);
  dfs3(1, 0, 0);
  for (int i = 1; i <= n; i++) printf("%lld ", ans[i]);
  return 0;
}
