#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
const int MAXN = 210000;
const long long P = 1000000000 + 7;
vector<int> e[MAXN];
long long dp[MAXN], ans[MAXN];
vector<long long> dpp[MAXN], dps[MAXN];
void dfs(int v, int p) {
  dp[v] = 1;
  dpp[v].push_back(1);
  for (int u : e[v]) {
    if (u == p) continue;
    dfs(u, v);
    dp[v] *= dp[u] + 1;
    dp[v] %= P;
    dpp[v].push_back(dp[v]);
  }
  dps[v].push_back(1);
  for (int i = (int)(e[v].size()) - 1; i >= 0; --i) {
    int u = e[v][i];
    if (u == p) continue;
    long long x = dps[v].back() * (dp[u] + 1) % P;
    dps[v].push_back(x);
  }
}
void dfs2(int v, int p) {
  ans[v] = dp[v];
  if (p != -1) ans[v] *= dp[p] + 1, ans[v] %= P;
  long long org = dp[v];
  int m = e[v].size() - (p != -1);
  int i = 0;
  for (int u : e[v]) {
    if (u == p) continue;
    dp[v] = dpp[v][i] * dps[v][m - i - 1] % P;
    if (p != -1) dp[v] *= dp[p] + 1, dp[v] %= P;
    dfs2(u, v);
    ++i;
  }
  dp[v] = org;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int N;
  cin >> N;
  for (int i = 0; i < (int)(N - 1); ++i) {
    int p;
    cin >> p;
    --p;
    e[i + 1].push_back(p);
    e[p].push_back(i + 1);
  }
  dfs(0, -1);
  dfs2(0, -1);
  for (int i = 0; i < (int)(N); ++i) cout << ans[i] << ' ';
  cout << '\n';
  return 0;
}
