#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int mod = 1000000007, n;
pair<int, int> r[200005];
vector<int> g[200005];
int ans[200005];
int val(int x, int st) {
  if (st == 0) return 1;
  long long z = val(x, st / 2);
  int res;
  if (st & 1) {
    res = (((z * x) % mod) * z) % mod;
  } else {
    res = (z * z) % mod;
  }
  return res;
}
void culc(int cur, int p) {
  r[cur].second = 1;
  for (int i = 0; i < g[cur].size(); i++) {
    if (g[cur][i] == p) continue;
    culc(g[cur][i], cur);
    if (r[g[cur][i]].second * (!r[g[cur][i]].first) + 1 == mod) {
      r[cur].first++;
    } else
      r[cur].second =
          ((long long)r[cur].second *
           ((long long)r[g[cur][i]].second * (!r[g[cur][i]].first) + 1)) %
          mod;
  }
}
void dfs(int cur, int par) {
  if (par == -1) {
    ans[cur] = (r[cur].first > 0 ? 0 : r[cur].second);
    for (int i = 0; i < g[cur].size(); i++) dfs(g[cur][i], cur);
    return;
  }
  pair<int, int> mem = r[cur];
  int newpar;
  if (r[cur].second + 1 == mod && r[par].first == 1) {
    newpar = r[par].second;
  } else {
    if (r[par].first > 0)
      newpar = 0;
    else
      newpar = ((long long)val(r[cur].second * (!r[cur].first) + 1, mod - 2) *
                (long long)r[par].second) %
               mod;
  }
  pair<int, int> newcur = make_pair(0, 1);
  for (int i = 0; i < g[cur].size(); i++) {
    if (g[cur][i] == par) {
      if (newpar + 1 == mod) {
        newcur.first++;
      } else {
        newcur.second =
            ((long long)(newpar + 1) * (long long)newcur.second) % mod;
      }
      continue;
    }
    if (r[g[cur][i]].second * (!r[g[cur][i]].first) + 1 == mod) {
      newcur.first++;
    } else
      newcur.second =
          ((long long)newcur.second *
           (long long)(r[g[cur][i]].second * (!r[g[cur][i]].first) + 1)) %
          mod;
  }
  ans[cur] = (newcur.first > 0 ? 0 : newcur.second);
  r[cur] = newcur;
  for (int i = 0; i < g[cur].size(); i++) {
    if (g[cur][i] == par) continue;
    dfs(g[cur][i], cur);
  }
  r[cur] = mem;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    g[x].push_back(i);
    g[i].push_back(x);
  }
  culc(1, -1);
  dfs(1, -1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
