#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
inline long long power(long long a, long long b) {
  long long multiply = 1;
  for (int i = (0); i < (b); i++) {
    multiply *= a;
  }
  return multiply;
}
const int N = 2e5 + 7;
int n;
long long f[N], g[N], ans[N];
vector<int> graph[N];
vector<long long> prefix[N], suffix[N];
void calc_f(int u, int p = -1) {
  f[u] = 1LL;
  for (auto v : graph[u]) {
    if (v == p) continue;
    calc_f(v, u);
    f[u] *= (f[v] + 1);
    f[u] %= 1000000007LL;
  }
  long long pref = 1;
  long long suff = 1;
  for (int j = (0); j < (graph[u].size()); j++) {
    int v = graph[u][j];
    if (v == p) {
      prefix[u].push_back(0);
      continue;
    }
    prefix[u].push_back(pref);
    pref = (pref * (f[v] + 1)) % 1000000007LL;
  }
  for (int j = ((int)graph[u].size() - 1); j >= (0); j--) {
    int v = graph[u][j];
    if (v == p) {
      suffix[u].push_back(0);
      continue;
    }
    suffix[u].push_back(suff);
    suff = (suff * (f[v] + 1)) % 1000000007LL;
  }
  reverse(suffix[u].begin(), suffix[u].end());
}
void calc_g(int u, int p = -1) {
  if (p == -1) ans[u] = f[u];
  for (int j = (0); j < (graph[u].size()); j++) {
    int v = graph[u][j];
    if (v == p) continue;
    g[u] = (prefix[u][j] * suffix[u][j]) % 1000000007LL;
    if (p != -1) g[u] = (g[u] * (g[p] + 1)) % 1000000007LL;
    ans[v] = (f[v] * (g[u] + 1)) % 1000000007LL;
    calc_g(v, u);
  }
}
int main() {
  int test, cases = 1;
  scanf("%d", &n);
  int x;
  for (int i = (2); i < (n + 1); i++) {
    scanf("%d", &x);
    graph[x].push_back(i);
    graph[i].push_back(x);
  }
  calc_f(1);
  calc_g(1);
  for (int i = (1); i < (n + 1); i++) printf("%lld ", ans[i]);
  puts("");
  return 0;
}
