#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
vector<long long> V[N], V1[N], O[N], S[N];
long long n, m, i, j, k, l, s, t, d, u, ii, jj, x, y, z, h[N], hh[N], hhh[N];
long long f(long long x, long long root, long long tt) {
  if (d and root) {
    long long t = 1, i, u = V1[root].size();
    i = hhh[x];
    t = O[root][i] * S[root][u - i - 1] % 1000000007 * (tt) % 1000000007;
    h[x] = h[x] * (tt) % 1000000007;
  }
  if (!d) h[x] = 1;
  long long t = 1, i, j, u = V[x].size();
  for (i = 0; i < u; i++) {
    if (V[x][i] != root) {
      j = f(V[x][i], x,
            d ? ((tt)*O[x][i] % 1000000007 * S[x][u - i - 1] % 1000000007 + 1) %
                    1000000007
              : 0);
      if (!d) {
        V1[x].push_back(j + 1);
        h[x] *= (j + 1);
        h[x] %= 1000000007;
      }
    } else if (!d) {
      V1[x].push_back(1);
      hhh[x] = i;
    }
  }
  if (!d) {
    t = 1;
    for (i = 0; i < u; i++) {
      O[x].push_back(t);
      t *= V1[x][i];
      t %= 1000000007;
    }
    t = 1;
    for (i = u - 1; i >= 0; i--) {
      S[x].push_back(t);
      t *= V1[x][i];
      t %= 1000000007;
    }
  }
  return h[x];
}
int main() {
  cin >> n;
  for (i = 2; i <= n; i++) {
    scanf("%lld", &x);
    V[x].push_back(i);
    V[i].push_back(x);
  }
  f(1, 0, 0);
  d = 1;
  f(1, 0, 1);
  for (i = 1; i <= n; i++) printf("%lld ", h[i]);
}
