#include <bits/stdc++.h>
using namespace std;
vector<int> v[300005];
int viz[300005], d[300005], sol[300005];
void gcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
  } else {
    long long x0, y0;
    gcd(b, a % b, x0, y0);
    x = y0;
    y = 0LL + x0 - 1LL * (a / b) * y0;
  }
}
long long invs(int a) {
  long long x, y;
  x = 0;
  gcd(a, 1000000007, x, y);
  if (x <= 0) x = 0LL + 1000000007 + x % 1000000007;
  return x;
}
void dfs(int nod) {
  int frz;
  viz[nod] = 1;
  frz = 1;
  d[nod] = 1;
  for (vector<int>::iterator it = v[nod].begin(); it != v[nod].end(); it++)
    if (viz[*it] == 0) {
      dfs(*it);
      frz = 0;
      d[nod] = (1LL * d[nod] * (d[*it] + 1)) % 1000000007;
    }
  if (frz) d[nod] = 1;
}
void dfs2(int nod, int x) {
  int y, nr, i, j, n;
  int *l, *r, *aux;
  viz[nod] = 1;
  y = (1LL * d[nod] * (x + 1)) % 1000000007;
  sol[nod] = y % 1000000007;
  nr = 0;
  aux = new int[v[nod].size() + 1];
  for (vector<int>::iterator it = v[nod].begin(); it != v[nod].end(); it++)
    if (viz[*it] == 0) aux[++nr] = d[*it] + 1;
  l = new int[nr + 2];
  r = new int[nr + 2];
  l[0] = 1;
  r[nr + 1] = (x + 1) % 1000000007;
  for (i = 1; i <= nr; i++) l[i] = (1LL * aux[i] * l[i - 1]) % 1000000007;
  for (i = nr; i >= 1; i--) r[i] = (1LL * aux[i] * r[i + 1]) % 1000000007;
  i = 0;
  for (vector<int>::iterator it = v[nod].begin(); it != v[nod].end(); it++)
    if (viz[*it] == 0) {
      i++;
      dfs2(*it, (1LL * l[i - 1] * r[i + 1]) % 1000000007);
    }
  delete (l);
  delete (r);
  delete (aux);
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, i, x;
  cin >> n;
  for (i = 2; i <= n; i++) {
    cin >> x;
    v[i].push_back(x);
    v[x].push_back(i);
  }
  dfs(1);
  memset(viz, 0, sizeof(viz));
  dfs2(1, 0);
  for (i = 1; i <= n; i++) cout << sol[i] << " ";
  return 0;
}
