#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 300;
const int md = 1000000007;
vector<int> g[N], pref[N], suf[N];
int ans[N], d[N];
void dfs(int s) {
  d[s] = 1;
  for (int i = 0; i < int(int((g[s]).size())); i++) {
    int to = g[s][i];
    dfs(to);
    d[s] = d[s] * 1ll * (d[to] + 1) % md;
  }
  int curp = 1, curs = 1;
  for (int i = 0; i < int(int((g[s]).size())); i++) {
    int to = g[s][i], rto = g[s][int((g[s]).size()) - i - 1];
    pref[s].push_back(curp);
    suf[s].push_back(curs);
    curp = curp * 1ll * (d[to] + 1) % md;
    curs = curs * 1ll * (d[rto] + 1) % md;
  }
  reverse(suf[s].begin(), suf[s].end());
}
void tdfs(int s, int par = -1) {
  ans[s] = d[s];
  for (int i = 0; i < int(int((g[s]).size())); i++) {
    int to = g[s][i], olds = d[s], oldto = d[to];
    d[s] = pref[s][i] * 1ll * suf[s][i] % md;
    if (par != -1) d[s] = d[s] * 1ll * (d[par] + 1) % md;
    d[to] = d[to] * 1ll * (d[s] + 1) % md;
    tdfs(to, s);
    d[s] = olds;
    d[to] = oldto;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int par;
    scanf("%d", &par);
    g[par - 1].push_back(i + 1);
  }
  dfs(0);
  tdfs(0);
  for (int i = 0; i < int(n); i++) {
    if (i > 0) printf(" ");
    printf("%d", ans[i]);
  }
}
