#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7, n = 2e5;
vector<int> e[n];
vector<long long> pref[n], suf[n];
long long dp[n];
int ans[n];
void mult(long long &a, long long b) { a = a * b % md; }
void dfs(int v = 0, int p = -1) {
  vector<long long> suf, pref;
  for (int to : e[v])
    if (to != p) {
      dfs(to, v);
      pref.push_back(dp[to] + 1);
      suf.push_back(dp[to] + 1);
    }
  for (int i = 1, j = suf.size() - 2; i < pref.size(); i++, j--) {
    mult(pref[i], pref[i - 1]);
    mult(suf[j], suf[j + 1]);
  }
  dp[v] = pref.empty() ? 1 : pref.back();
  ::pref[v] = pref;
  ::suf[v] = suf;
}
long long f(const vector<long long> &a, int i) {
  return i < 0 || a.size() - 1 < i ? 1 : a[i];
}
void tdfs(int v = 0, int p = -1, long long pony = 0) {
  int j = -1;
  ans[v] = dp[v] * (pony + 1) % md;
  for (int to : e[v])
    if (to != p) {
      j++;
      long long newPony = (1 + pony) * f(pref[v], j - 1) % md;
      mult(newPony, f(suf[v], j + 1));
      tdfs(to, v, newPony);
    }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int x = 1, y; x < n; x++) {
    scanf("%d", &y);
    y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs();
  tdfs();
  for (int i = 0; i < n; i++) {
    printf("%lld ", ans[i]);
  }
  exit(0);
}
