#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int n, t[200010], dp[200010], ans[200010], fa[200010], qzj[200010], hzj[200010];
vector<int> g[200010];
void dfs1(int u) {
  dp[u] = 1;
  int len = g[u].size();
  for (int i = 0; i < len; i++) {
    dfs1(g[u][i]);
    dp[u] = (1LL * dp[u] * (dp[g[u][i]] + 1)) % Mod;
  }
  if (len != 0) {
    qzj[g[u][0]] = 1;
    hzj[g[u][len - 1]] = 1;
    for (int i = 1; i < len; i++)
      qzj[g[u][i]] = 1LL * qzj[g[u][i - 1]] * (dp[g[u][i - 1]] + 1) % Mod;
    for (int i = len - 2; i >= 0; i--)
      hzj[g[u][i]] = 1LL * hzj[g[u][i + 1]] * (dp[g[u][i + 1]] + 1) % Mod;
  }
}
void dfs2(int u) {
  if (u != 1) ans[u] = 1LL * dp[u] * (t[fa[u]] + 1) % Mod;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    t[u] = 1LL * qzj[v] * hzj[v] % Mod * (t[fa[u]] + 1) % Mod;
    dfs2(v);
  }
}
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int u;
    cin >> u;
    g[u].push_back(i);
    fa[i] = u;
  }
  dfs1(1);
  ans[1] = dp[1];
  dfs2(1);
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
