#include <bits/stdc++.h>
const long long MaxN = 2e5 + 50;
const long long p = 1e9 + 7;
template <class t>
inline void read(t &s) {
  s = 0;
  register long long f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  long long buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool checkmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool checkmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
std::vector<long long> E[MaxN];
long long n;
long long f[MaxN], g[MaxN], h[MaxN];
inline long long fpow(long long a, long long b) {
  register long long res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) res = res * a % p;
  return res;
}
inline void dfs(long long u, long long fa) {
  std::vector<std::pair<long long, long long> > dr;
  f[u] = 1;
  for (auto v : E[u])
    if (v != fa)
      dfs(v, u), (f[u] *= (f[v] + 1LL) % p) %= p,
          dr.push_back(std::make_pair((f[v] + 1LL) % p, v));
  if ((long long)dr.size()) {
    std::vector<long long> pre((long long)dr.size()), suf((long long)dr.size());
    pre[0] = dr[0].first,
    suf[(long long)dr.size() - 1] = dr[(long long)dr.size() - 1].first;
    for (long long i = 1; i < (long long)dr.size(); ++i)
      pre[i] = pre[i - 1] * dr[i].first % p;
    for (long long i = (long long)dr.size() - 2; ~i; --i)
      suf[i] = suf[i + 1] * dr[i].first % p;
    for (long long i = 0; i < (long long)dr.size(); ++i) {
      register long long s = 1;
      if (i - 1 >= 0) (s *= pre[i - 1]) %= p;
      if (i + 1 < (long long)dr.size()) (s *= suf[i + 1]) %= p;
      h[dr[i].second] = s;
    }
  }
}
inline void dfs2(long long u, long long fa) {
  for (auto v : E[u])
    if (v != fa) g[v] = (g[u] * h[v] % p + 1LL) % p, dfs2(v, u);
}
signed main(void) {
  read(n);
  register long long v;
  for (long long i = 2; i <= n; ++i)
    read(v), E[i].push_back(v), E[v].push_back(i);
  dfs(1, 0), g[1] = 1, dfs2(1, 0);
  for (long long i = 1; i <= n; ++i) write(g[i] * f[i] % p), std::putchar(32);
  std::puts("");
  return 0;
}
