#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n;
vector<vector<int> > g;
vector<int> ans;
vector<vector<int> > vals;
vector<vector<int> > suff, pref;
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  if (a < 0) a += MOD;
  return a;
}
int mul(long long a, int b) {
  a *= b;
  a %= MOD;
  return a;
}
int modpow(int a, int n) {
  if (n == 0) return 1;
  if (n % 2 == 0) return modpow(mul(a, a), n / 2);
  return mul(a, modpow(a, n - 1));
}
int inv(int a) { return modpow(a, MOD - 2); }
int dfs(int v, int p) {
  for (auto& u : g[v]) {
    if (u == p) continue;
    vals[v].push_back(dfs(u, v));
  }
  int res = 1;
  for (int(i) = (0); (i) < ((int((vals[v]).size()))); (i)++) {
    res = mul(res, add(1, vals[v][i]));
  }
  return res;
}
void dfs2(int v, int p, int above) {
  pref[v].resize((int((vals[v]).size())));
  suff[v].resize((int((vals[v]).size())));
  int prod = 1;
  for (int(i) = (0); (i) < ((int((vals[v]).size()))); (i)++) {
    prod = mul(prod, add(1, vals[v][i]));
    pref[v][i] = prod;
  }
  prod = 1;
  for (int i = (int((vals[v]).size())) - 1; i >= 0; i--) {
    prod = mul(prod, add(1, vals[v][i]));
    suff[v][i] = prod;
  }
  ans[v] = mul(prod, add(1, above));
  int pos = 0;
  for (auto& u : g[v]) {
    if (u == p) continue;
    int l = 1;
    int r = 1;
    if (pos - 1 >= 0) l = pref[v][pos - 1];
    if (pos + 1 <= (int((vals[v]).size())) - 1) r = suff[v][pos + 1];
    int aboveU = mul(mul(l, r), add(above, 1));
    dfs2(u, v, aboveU);
    pos++;
  }
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0);
  cin >> n;
  g.resize(n);
  vals.resize(n);
  ans.assign(n, 0);
  pref.resize(n);
  suff.resize(n);
  for (int(i) = (1); (i) < (n); (i)++) {
    int tmp;
    cin >> tmp;
    tmp--;
    g[i].push_back(tmp);
    g[tmp].push_back(i);
  }
  dfs(0, -1);
  dfs2(0, 0, 0);
  for (int(i) = (0); (i) < (n); (i)++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
