#include <bits/stdc++.h>
using namespace std;
bool debug;
const int inf = 1e9 + 5;
const long long INF = (long long)inf * inf;
const int nax = 2e5 + 5;
const long long mod = 1e9 + 7;
map<pair<int, int>, pair<int, int> > m;
vector<int> w[nax];
const pair<int, int> NIC = make_pair(-1, -1);
int res[nax];
pair<int, int> daj(pair<int, int> p) {
  auto it = m.find(p);
  if (it == m.end()) return NIC;
  return (*it).second;
}
int dol[nax];
void mnoz(int &a, int b) { a = (long long)a * b % mod; }
int pot(int a, int b) {
  int pom = 1;
  while (b) {
    if (b % 2) mnoz(pom, a);
    b /= 2;
    mnoz(a, a);
  }
  return pom;
}
int odw(int a) { return pot(a, mod - 2); }
void dfs(int a) {
  dol[a] = 1;
  for (auto b : w[a])
    if (b > a) {
      dfs(b);
      mnoz(dol[a], 1 + dol[b]);
    }
}
void dfs2(int a, int gora) {
  if (gora >= mod) gora -= mod;
  vector<int> licz;
  for (auto b : w[a])
    if (b > a)
      if ((dol[b] + 1) % mod == 0) licz.push_back(b);
  if ((int)licz.size() >= 2) {
    res[a] = 0;
    for (auto b : w[a])
      if (b > a) dfs2(b, 1);
  } else if ((int)licz.size() == 1) {
    res[a] = 0;
    int spec = licz[0];
    for (auto b : w[a])
      if (b > a && b != spec) mnoz(gora, dol[b] + 1);
    dfs2(spec, gora + 1);
    for (auto b : w[a])
      if (b > a && b != spec) dfs2(b, 1);
  } else {
    for (auto b : w[a])
      if (b > a) mnoz(gora, dol[b] + 1);
    res[a] = gora;
    for (auto b : w[a])
      if (b > a) {
        mnoz(gora, odw(dol[b] + 1));
        dfs2(b, 1 + gora);
        mnoz(gora, dol[b] + 1);
      }
  }
}
int main(int argc, char *argv[]) {
  debug = argc > 1;
  assert(50LL * odw(50) % mod == 1);
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int b;
    scanf("%d", &b);
    w[i].push_back(b);
    w[b].push_back(i);
  }
  dfs(1);
  dfs2(1, 1);
  for (int i = 1; i <= n; ++i) printf("%d ", res[i]);
  puts("");
  return 0;
}
