#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
long long up[200005], down[200005];
std::vector<int> edge[200005];
int n;
void dfs(int u) {
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    dfs(v);
    long long ans = (1 + down[v]) % MOD;
    down[u] = down[u] * ans % MOD;
  }
}
long long quick(long long a, int x) {
  long long ans = 1;
  while (x) {
    if (x & 1) ans = ans * a % MOD;
    x >>= 1;
    a = a * a % MOD;
  }
  return ans;
}
void dfs1(int u) {
  int m = edge[u].size();
  std::vector<long long> v(m + 1), v1(m + 1);
  for (int i = 0; i < m; i++) v[i] = v1[i] = down[edge[u][i]] + 1;
  for (int i = 1; i < m; i++) v[i] = v[i] * v[i - 1] % MOD;
  for (int i = m - 2; i >= 0; i--) v1[i] = v1[i] * v1[i + 1] % MOD;
  for (int i = 0; i < m; i++) {
    int vv = edge[u][i];
    long long ans = 1;
    if (i >= 1) ans = ans * v[i - 1] % MOD;
    if (i < m - 1) ans = ans * v1[i + 1] % MOD;
    up[vv] = (ans * up[u] % MOD + 1) % MOD;
    dfs1(vv);
  }
}
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int a;
    cin >> a;
    edge[a].push_back(i);
  }
  for (int i = 1; i <= n; i++) down[i] = 1, up[i] = 1;
  dfs(1);
  dfs1(1);
  for (int i = 1; i <= n; i++) {
    cout << up[i] * down[i] % MOD << ' ';
  }
  return 0;
}
