#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
const int MAXM = MAXN - 1;
const int MOD = 1000000007;
const inline int mymult(int a, int b) { return (long long)a * b % MOD; }
const inline int myadd(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int n;
int fst[MAXN], lst[MAXN], prv[2 * MAXM], nxt[2 * MAXM], to[2 * MAXM];
int upto[MAXN];
int wayspre[2 * MAXM], wayspost[2 * MAXM];
int ways[2 * MAXM];
int xxx = 0;
int calc(int x) {
  int at = to[x];
  if (ways[x] != -1) return ways[x];
  if (upto[at] == -1) {
    upto[at] = x ^ 1;
    int cur = 1;
    for (int y = fst[at]; y != -1; y = nxt[y]) {
      wayspre[y] = cur;
      if (y == upto[at]) break;
      cur = mymult(cur, calc(y));
    }
    cur = 1;
    for (int y = lst[at]; y != -1; y = prv[y]) {
      wayspost[y] = cur;
      if (y == upto[at]) break;
      cur = mymult(cur, calc(y));
    }
  } else if (upto[at] != -2) {
    int cur = wayspre[upto[at]];
    for (int y = upto[at]; y != -1; y = nxt[y]) {
      wayspre[y] = cur;
      cur = mymult(cur, calc(y));
    }
    cur = wayspost[upto[at]];
    for (int y = upto[at]; y != -1; y = prv[y]) {
      wayspost[y] = cur;
      cur = mymult(cur, calc(y));
    }
    upto[at] = -2;
  }
  ways[x] = myadd(mymult(wayspre[x ^ 1], wayspost[x ^ 1]), 1);
  return ways[x];
}
int ret[MAXN];
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) fst[i] = lst[i] = -1;
  for (int i = (0); i < (n - 1); ++i) {
    int a = i + 1, b;
    scanf("%d", &b);
    --b;
    prv[2 * i + 0] = lst[a];
    lst[a] = 2 * i + 0;
    nxt[2 * i + 0] = -1;
    if (prv[2 * i + 0] == -1)
      fst[a] = 2 * i + 0;
    else
      nxt[prv[2 * i + 0]] = 2 * i + 0;
    to[2 * i + 0] = b;
    prv[2 * i + 1] = lst[b];
    lst[b] = 2 * i + 1;
    nxt[2 * i + 1] = -1;
    if (prv[2 * i + 1] == -1)
      fst[b] = 2 * i + 1;
    else
      nxt[prv[2 * i + 1]] = 2 * i + 1;
    to[2 * i + 1] = a;
  }
  memset(ways, -1, sizeof(ways));
  memset(upto, -1, sizeof(upto));
  for (int i = (0); i < (n); ++i) {
    ret[i] = 1;
    for (int x = fst[i]; x != -1; x = nxt[x]) ret[i] = mymult(ret[i], calc(x));
  }
  for (int i = (0); i < (n); ++i) {
    if (i != 0) printf(" ");
    printf("%d", ret[i]);
  }
  puts("");
}
int main() {
  run();
  return 0;
}
