#include <bits/stdc++.h>
using namespace std;
const int max_n = 200010;
const int MOD = 1e9 + 7;
vector<int> child[max_n];
vector<long long> pre[max_n];
vector<long long> suf[max_n];
long long down[max_n], up[max_n], ans[max_n];
void dfs1(int v) {
  down[v] = 1;
  for (int i = 0; i < child[v].size(); i++) {
    int u = child[v][i];
    suf[v].push_back(down[v]);
    dfs1(u);
    down[v] = (down[v] * (down[u] + 1)) % MOD;
  }
  long long num = 1;
  for (int i = child[v].size() - 1; i >= 0; i--) {
    int u = child[v][i];
    pre[v].push_back(num);
    num = num * (down[u] + 1) % MOD;
  }
  reverse(pre[v].begin(), pre[v].end());
}
void dfs2(int v) {
  for (int i = 0; i < child[v].size(); i++) {
    int u = child[v][i];
    up[u] = ((up[v] * suf[v][i] % MOD) * pre[v][i] + 1) % MOD;
    ans[u] = (up[u] * down[u]) % MOD;
    dfs2(u);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    child[p].push_back(i);
  }
  dfs1(1);
  up[1] = 1;
  dfs2(1);
  ans[1] = down[1];
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
