#include <bits/stdc++.h>
using namespace std;
char gchar() {
  static char tbuf1[1000], *tmp_st = tbuf1, *tmp_ed = tbuf1;
  if (tmp_st == tmp_ed) {
    int len = fread(tbuf1, 1, 1000, stdin);
    if (len == 0) return -1;
    tmp_ed = tbuf1 + len;
    tmp_st = tbuf1;
  }
  return *(tmp_st++);
}
inline bool gn(int& first) {
  char c, sg = 0;
  while (c = gchar(), (c > '9' || c < '0') && c != '-' && ~c)
    ;
  if (c == -1) return 0;
  for ((c == '-' ? sg = 1, c = gchar() : 0), first = 0; c >= '0' && c <= '9';
       c = gchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
  return 1;
}
inline void print(int first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
inline int inv(int first) {
  if (first < 2) return first;
  return (long long)1000000007 / first *
         (1000000007 - inv(1000000007 % first)) % 1000000007;
}
inline pair<int, int> operator*(pair<int, int> a, int first) {
  if (first % 1000000007 == 0) return pair<int, int>(a.first, a.second + 1);
  return pair<int, int>((long long)a.first * first % 1000000007, a.second);
}
inline pair<int, int> operator/(pair<int, int> a, int first) {
  if (first % 1000000007 == 0) return pair<int, int>(a.first, a.second - 1);
  return pair<int, int>((long long)a.first * inv(first) % 1000000007, a.second);
}
int dp[200001];
vector<int> adj[200001];
pair<int, int> all[200001], tmp;
inline void dfs(int u) {
  all[u] = pair<int, int>(1, 0);
  for (int v : adj[u]) {
    dfs(v);
    all[u] = all[u] * (dp[v] + 1);
  }
  dp[u] = all[u].second ? 0 : all[u].first;
}
inline void rdfs(int u, int up = 0) {
  dp[u] = (long long)dp[u] * (up + 1) % 1000000007;
  all[u] = all[u] * (up + 1);
  for (int v : adj[u]) {
    tmp = all[u] / (dp[v] + 1);
    rdfs(v, tmp.second ? 0 : tmp.first);
  }
}
int main() {
  int n;
  gn(n);
  for (int i = 2, pa; i <= n; i++) {
    gn(pa);
    adj[pa].push_back(i);
  }
  dfs(1), rdfs(1);
  for (int i = 1; i <= n; i++) printsp(dp[i]);
}
