import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class D_Round_302_Div1 {

	public static long MOD = 1000000007;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		ArrayList<Integer>[] map = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			map[i] = new ArrayList();
		}
		for (int i = 0; i < n - 1; i++) {
			int v = in.nextInt() - 1;
			map[v].add(i + 1);
			map[i + 1].add(v);
		}
		long[] count = new long[n];
		long[]result = new long[n];
		cal1(0,0,count, map);
		//System.out.println(Arrays.toString(count));
		cal(0,0,count, result, map);
		for(long i : result){
			out.print(i + " ");
		}
		out.close();
	}

	public static long cal1(int node, int pa, long[] count,
			ArrayList<Integer>[] map) {
		count[node] = 1;
		for (int i : map[node]) {
			if (i != pa) {
				count[node] *= (cal1(i, node, count, map) + 1);
				count[node] %= MOD;
			}
		}
		return count[node];
	}

	public static void cal(int node, int pa, long[]count, long[]re, ArrayList<Integer>[]map){

		if(node == pa){
			re[node] = count[node];
		}else{
			BigInteger x = BigInteger.valueOf(re[pa]).multiply(BigInteger.valueOf((count[node] + 1)%MOD).modInverse(BigInteger.valueOf(MOD))).mod(BigInteger.valueOf(MOD));
			long tmp = (x.longValue() + 1)%MOD;
			re[node] = count[node]*tmp;
			re[node] %= MOD;
		}
		for(int i : map[node]){
			if(i != pa){
				cal(i, node, count, re, map);
			}
		}

	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

		public Point(int start, int end) {
			this.x = start;
			this.y = end;
		}

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class D_Round_302_Div1 {

	public static long MOD = 1000000007;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		ArrayList<Integer>[] map = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			map[i] = new ArrayList();
		}
		for (int i = 0; i < n - 1; i++) {
			int v = in.nextInt() - 1;
			map[v].add(i + 1);
			map[i + 1].add(v);
		}
		long[] count = new long[n];
		long[] result = new long[n];
		int[] p = new int[n];
		cal1(0, 0, p, count, map);
		// System.out.println(Arrays.toString(count));

		cal(0, 0, p, count, result, map);
		for (long i : result) {
			out.print(i + " ");
		}
		out.close();
	}

	public static long cal1(int node, int pa, int[] p, long[] count,
			ArrayList<Integer>[] map) {
		count[node] = 1;
		p[node] = pa;
		for (int i : map[node]) {
			if (i != pa) {
				count[node] *= (cal1(i, node, p, count, map) + 1) % MOD;
				count[node] %= MOD;
			}
		}
		return count[node];
	}

	public static void cal(int node, int pa, int[] p, long[] count, long[] re,
			ArrayList<Integer>[] map) {

		if (node == pa) {
			re[node] = count[node];
		} else {
			if (count[node] + 1 == MOD) {
				long tmp = 1;
				for (int i : map[pa]) {
					if (i != p[pa] && i != node) {
						tmp *= count[i] + 1;
						tmp %= MOD;
					} else if(i == p[pa]){
						BigInteger x = BigInteger
								.valueOf(re[p[pa]])
								.multiply(
										BigInteger
												.valueOf(
														(count[pa] + 1) % MOD)
												.modInverse(
														BigInteger.valueOf(MOD)))
								.mod(BigInteger.valueOf(MOD));
						tmp *= (x.longValue() + 1) % MOD;
						tmp %= MOD;
					}
				}
				re[node] = count[node]*(tmp + 1);
				re[node] %= MOD;

			} else {
				BigInteger x = BigInteger
						.valueOf(re[pa])
						.multiply(
								BigInteger.valueOf((count[node] + 1) % MOD)
										.modInverse(BigInteger.valueOf(MOD)))
						.mod(BigInteger.valueOf(MOD));
				long tmp = (x.longValue() + 1) % MOD;
				re[node] = count[node] * tmp;
				re[node] %= MOD;
			}

		}
		for (int i : map[node]) {
			if (i != pa) {
				cal(i, node, p, count, re, map);
			}
		}

	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

		public Point(int start, int end) {
			this.x = start;
			this.y = end;
		}

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class D_Round_302_Div1 {

	public static long MOD = 1000000007;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		ArrayList<Integer>[] map = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			map[i] = new ArrayList();
		}
		for (int i = 0; i < n - 1; i++) {
			int v = in.nextInt() - 1;
			map[v].add(i + 1);
			map[i + 1].add(v);
		}
		long[] count = new long[n];
		long[] result = new long[n];
		cal1(0, 0, count, map);
		// System.out.println(Arrays.toString(count));
		cal(0, 0, count, result, map);
		for (long i : result) {
			out.print(i + " ");
		}
		out.close();
	}

	public static long cal1(int node, int pa, long[] count,
			ArrayList<Integer>[] map) {
		count[node] = 1;
		for (int i : map[node]) {
			if (i != pa) {
				count[node] *= (cal1(i, node, count, map) + 1) % MOD;
				count[node] %= MOD;
			}
		}
		return count[node];
	}

	public static void cal(int node, int pa, long[] count, long[] re,
			ArrayList<Integer>[] map) {

		if (node == pa) {
			re[node] = count[node];
		} else {
			if (count[node] + 1 == MOD) {

			} else {
				BigInteger x = BigInteger
						.valueOf(re[pa])
						.multiply(
								BigInteger.valueOf((count[node] + 1) % MOD)
										.modInverse(BigInteger.valueOf(MOD)))
						.mod(BigInteger.valueOf(MOD));
				long tmp = (x.longValue() + 1) % MOD;
				re[node] = count[node] * tmp;
				re[node] %= MOD;
			}

		}
		for (int i : map[node]) {
			if (i != pa) {
				cal(i, node, count, re, map);
			}
		}

	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

		public Point(int start, int end) {
			this.x = start;
			this.y = end;
		}

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class D_Round_302_Div1 {

	public static long MOD = 1000000007;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		ArrayList<Integer>[] map = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			map[i] = new ArrayList();
		}
		for (int i = 0; i < n - 1; i++) {
			int v = in.nextInt() - 1;
			map[v].add(i + 1);
			map[i + 1].add(v);
		}
		long[] count = new long[n];
		long[]result = new long[n];
		cal1(0,0,count, map);
		//System.out.println(Arrays.toString(count));
		cal(0,0,count, result, map);
		for(long i : result){
			out.print(i + " ");
		}
		out.close();
	}

	public static long cal1(int node, int pa, long[] count,
			ArrayList<Integer>[] map) {
		count[node] = 1;
		for (int i : map[node]) {
			if (i != pa) {
				count[node] *= (cal1(i, node, count, map) + 1);
				count[node] %= MOD;
			}
		}
		return count[node];
	}

	public static void cal(int node, int pa, long[]count, long[]re, ArrayList<Integer>[]map){

		if(node == pa){
			re[node] = count[node];
		}else{
			BigInteger x = BigInteger.valueOf(re[pa]).multiply(BigInteger.valueOf(count[node] + 1).modInverse(BigInteger.valueOf(MOD))).mod(BigInteger.valueOf(MOD));
			long tmp = x.longValue() + 1;
			re[node] = count[node]*tmp;
			re[node] %= MOD;
		}
		for(int i : map[node]){
			if(i != pa){
				cal(i, node, count, re, map);
			}
		}

	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

		public Point(int start, int end) {
			this.x = start;
			this.y = end;
		}

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class D_Round_302_Div1 {

	public static long MOD = 1000000007;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		ArrayList<Integer>[] map = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			map[i] = new ArrayList();
		}
		for (int i = 0; i < n - 1; i++) {
			int v = in.nextInt() - 1;
			map[v].add(i + 1);
			map[i + 1].add(v);
		}
		long[] count = new long[n];
		long[] result = new long[n];
		cal1(0, 0, count, map);
		// System.out.println(Arrays.toString(count));
		cal(0, 0, count, result, map);
		for (long i : result) {
			out.print(i + " ");
		}
		out.close();
	}

	public static long cal1(int node, int pa, long[] count,
			ArrayList<Integer>[] map) {
		count[node] = 1;
		for (int i : map[node]) {
			if (i != pa) {
				count[node] *= (cal1(i, node, count, map) + 1) % MOD;
				count[node] %= MOD;
			}
		}
		return count[node];
	}

	public static void cal(int node, int pa, long[] count, long[] re,
			ArrayList<Integer>[] map) {

		if (node == pa) {
			re[node] = count[node];
		} else {
			if (re[pa] == 0 && count[node] + 1 == MOD) {

			} else {
				BigInteger x = BigInteger
						.valueOf(re[pa])
						.multiply(
								BigInteger.valueOf((count[node] + 1) % MOD)
										.modInverse(BigInteger.valueOf(MOD)))
						.mod(BigInteger.valueOf(MOD));
				long tmp = (x.longValue() + 1) % MOD;
				re[node] = count[node] * tmp;
				re[node] %= MOD;
			}

		}
		for (int i : map[node]) {
			if (i != pa) {
				cal(i, node, count, re, map);
			}
		}

	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

		public Point(int start, int end) {
			this.x = start;
			this.y = end;
		}

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class D_Round_302_Div1 {

	public static long MOD = 1000000007;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		ArrayList<Integer>[] map = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			map[i] = new ArrayList();
		}
		for (int i = 0; i < n - 1; i++) {
			int v = in.nextInt() - 1;
			map[v].add(i + 1);
			map[i + 1].add(v);
		}
		int[] count = new int[n];
		int[]result = new int[n];
		update(0,0,count, map);
		//System.out.println(Arrays.toString(count));
		cal(0,0,count, result, map);
		for(int i : result){
			out.print(i + " ");
		}
		out.close();
	}

	public static int update(int node, int pa, int[] count,
			ArrayList<Integer>[] map) {

		for (int i : map[node]) {
			if (i != pa) {
				count[node] += update(i, node, count, map);
			}
		}
		return 1 + count[node];
	}

	public static void cal(int node, int pa, int[]count, int[]re, ArrayList<Integer>[]map){
		long result = 1;

		for(int i : map[node]){
			if(i != pa){

				result *= count[i] + 2;
				result %= MOD;
			}else{
				result *= (count[i] - count[node]) + 1;
				result %= MOD;
				count[node] += (count[i] - count[node]);
			}
		}
		for(int i : map[node]){
			if(i != pa){
				cal(i, node, count,re, map);
			}
		}
		re[node] = (int)result;

	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

		public Point(int start, int end) {
			this.x = start;
			this.y = end;
		}

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}


//package round302;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[] par = new int[n];
		for(int i = 1;i < n;i++){
			par[i] = ni()-1;
		}
		par[0] = -1;
		int[][] g = parentToG(par);
		int mod = 1000000007;
		int[][] pars = parents3(g, 0);
		int[] ord = pars[1];

		long[] one = new long[n];
		for(int i = n-1;i >= 0;i--){
			int cur = ord[i];
			long o = 1;
			for(int e : g[cur]){
				if(par[cur] != e){
					o = o * (2 + one[e]) % mod;
				}
			}
			one[cur] = o-1;
			if(one[cur] < 0)one[cur] += mod;
		}
//		tr("one", one);
		long[] down = new long[n];

		for(int i = 0;i < n;i++){
			int cur = ord[i];
			int m = g[cur].length-(i==0?0:1);
			long[] lone = new long[m];
			int p = 0;
			for(int e : g[cur]){
				if(par[cur] != e){
					lone[p] = one[e] + 2;
					p++;
				}
			}

			if(p > 0){
				long[] left = new long[m+1];
				long[] right = new long[m+1];
				left[0] = 1;
				for(int j = 0;j < m;j++)left[j+1] = left[j] * lone[j] % mod;
				right[m] = 1;
				for(int j = m-1;j >= 0;j--)right[j] = right[j+1] * lone[j] % mod;

				int q = 0;
				for(int e : g[cur]){
					if(par[cur] != e){
						down[e] = (left[q] * right[q+1] % mod  * (down[cur]+1)+1 + mod - 1) % mod;
						q++;
					}
				}
			}
		}
		for(int i = 0;i < n;i++){
			if(i > 0)out.print(" ");
			out.print((one[i]+1)*(down[i]+1)%mod);
		}
		out.println();
	}

	public static int[][] parents3(int[][] g, int root) {
		int n = g.length;
		int[] par = new int[n];
		Arrays.fill(par, -1);

		int[] depth = new int[n];
		depth[0] = 0;

		int[] q = new int[n];
		q[0] = root;
		for (int p = 0, r = 1; p < r; p++) {
			int cur = q[p];
			for (int nex : g[cur]) {
				if (par[cur] != nex) {
					q[r++] = nex;
					par[nex] = cur;
					depth[nex] = depth[cur] + 1;
				}
			}
		}
		return new int[][] { par, q, depth };
	}

	public static int[][] parentToG(int[] par)
	{
		int n = par.length;
		int[] ct = new int[n];
		for(int i = 0;i < n;i++){
			if(par[i] >= 0){
				ct[i]++;
				ct[par[i]]++;
			}
		}
		int[][] g = new int[n][];
		for(int i = 0;i < n;i++){
			g[i] = new int[ct[i]];
		}
		for(int i = 0;i < n;i++){
			if(par[i] >= 0){
				g[par[i]][--ct[par[i]]] = i;
				g[i][--ct[i]] = par[i];
			}
		}
		return g;
	}

	static int[][] packU(int n, int[] from, int[] to) {
		int[][] g = new int[n][];
		int[] p = new int[n];
		for (int f : from)
			p[f]++;
		for (int t : to)
			p[t]++;
		for (int i = 0; i < n; i++)
			g[i] = new int[p[i]];
		for (int i = 0; i < from.length; i++) {
			g[from[i]][--p[from[i]]] = to[i];
			g[to[i]][--p[to[i]]] = from[i];
		}
		return g;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D2().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


//package round302;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[] par = new int[n];
		for(int i = 1;i < n;i++){
			par[i] = ni()-1;
		}
		par[0] = -1;
		int[][] g = parentToG(par);
		int mod = 1000000007;
		int[][] pars = parents3(g, 0);
		int[] ord = pars[1];

		long[] one = new long[n];
		for(int i = n-1;i >= 0;i--){
			int cur = ord[i];
			long o = 1;
			for(int e : g[cur]){
				if(par[cur] != e){
					o = o * (2 + one[e]) % mod;
				}
			}
			one[cur] = o-1;
			if(one[cur] < 0)one[cur] += mod;
		}
//		tr("one", one);
		long[] down = new long[n];

		for(int i = 0;i < n;i++){
			int cur = ord[i];
			long[] lone = new long[g[cur].length-(i == 0 ? 0 : 1)];
			long[] lret = new long[g[cur].length-(i == 0 ? 0 : 1)];
			int p = 0;
			for(int e : g[cur]){
				if(par[cur] != e){
					lone[p] = one[e] + 2;
					p++;
				}
			}
//			tr(lone);

			if(p > 0){
				long[][] lmul = new long[32-Integer.numberOfLeadingZeros(p)][];
				lmul[0] = lone;
				for(int d = 1;d < lmul.length;d++){
					lmul[d] = new long[(lmul[d-1].length+1)/2];
					Arrays.fill(lmul[d], 1L);
					for(int j = 0;j < lmul[d].length;j++){
						if(lmul[d-1].length >= 2*j+2){
							lmul[d][j] = lmul[d-1][2*j] * lmul[d-1][2*j+1] % mod;
						}else{
							lmul[d][j] = lmul[d-1][2*j];
						}
					}
				}
//				tr(lmul);
				for(int j = 0;j < p;j++){
					lret[j] = 1;
					int k = j;
					for(int d = 0;d < lmul.length;d++,k/=2){
						if(lmul[d].length >= (k^1)+1){
							lret[j] = lret[j] * lmul[d][k^1] % mod;
						}
					}
				}
//				tr("lret", lret);

				int q = 0;
				for(int e : g[cur]){
					if(par[cur] != e){
						down[e] = (lret[q++] * (down[cur]+1)+1 + mod - 1) % mod;
						// ((one[cur]+1)/(one[e]+2)*(one[e]+1)
						// (oc-oe)*oe/(oe+1)
					}
				}
			}
		}
		for(int i = 0;i < n;i++){
			if(i > 0)out.print(" ");
			out.print((one[i]+1)*(down[i]+1)%mod);
		}
		out.println();
	}

	public static int[][] parents3(int[][] g, int root) {
		int n = g.length;
		int[] par = new int[n];
		Arrays.fill(par, -1);

		int[] depth = new int[n];
		depth[0] = 0;

		int[] q = new int[n];
		q[0] = root;
		for (int p = 0, r = 1; p < r; p++) {
			int cur = q[p];
			for (int nex : g[cur]) {
				if (par[cur] != nex) {
					q[r++] = nex;
					par[nex] = cur;
					depth[nex] = depth[cur] + 1;
				}
			}
		}
		return new int[][] { par, q, depth };
	}

	public static int[][] parentToG(int[] par)
	{
		int n = par.length;
		int[] ct = new int[n];
		for(int i = 0;i < n;i++){
			if(par[i] >= 0){
				ct[i]++;
				ct[par[i]]++;
			}
		}
		int[][] g = new int[n][];
		for(int i = 0;i < n;i++){
			g[i] = new int[ct[i]];
		}
		for(int i = 0;i < n;i++){
			if(par[i] >= 0){
				g[par[i]][--ct[par[i]]] = i;
				g[i][--ct[i]] = par[i];
			}
		}
		return g;
	}

	static int[][] packU(int n, int[] from, int[] to) {
		int[][] g = new int[n][];
		int[] p = new int[n];
		for (int f : from)
			p[f]++;
		for (int t : to)
			p[t]++;
		for (int i = 0; i < n; i++)
			g[i] = new int[p[i]];
		for (int i = 0; i < from.length; i++) {
			g[from[i]][--p[from[i]]] = to[i];
			g[to[i]][--p[to[i]]] = from[i];
		}
		return g;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


#include<stdio.h>
#include<iostream>
#define MOD 1000000007
using namespace std;
int N,M,p[200100],d[200100],u[200100];

int pw(int x, int y) {
    if(y==0) {
        return 1;
    }
    int z = pw(x, y/2);
     z = (1LL*z*z) % MOD;
    if(y%2) {
        z = (1LL*z*x) % MOD;
    }
    return z;
}

int inv(int x) {
    return pw(x, MOD-2);
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif
    scanf("%d",&N);
    for(int i=2;i<=N;++i) {
        scanf("%d",&p[i]);
    }
    for(int i=1;i<=N;++i) {
        d[i] = 1;
        u[i] = 1;
    }

    for(int i=N;i>=1;--i) {
        d[p[i]] = (d[p[i]]*(d[i] + 1)) % MOD;
    }
    for(int i=2;i<=N;++i) {
        u[i] = (u[p[i]] + (1LL*d[p[i]] * inv((d[i]+1))) % MOD) %MOD;
    }

    for(int i=1;i<=N;++i) {
        int x = (1LL*d[i]*u[i]) % MOD;
        printf("%d ",x);
    }
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#define MOD 1000000007
using namespace std;
int N,M,p[200100],d[200100],u[200100];
vector<int> m[200100];

int main() {
	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif
    scanf("%d",&N);
    p[1] = 0;
    for(int i=2;i<=N;++i) {
        scanf("%d",&p[i]);
    }
    for(int i=1;i<=N;++i) {
        d[i] = 1;
        u[i] = 1;
        m[p[i]].push_back(i);
    }

    for(int i=N;i>=1;--i) {
        d[p[i]] = (1LL*d[p[i]]*(d[i] + 1)) % MOD;
    }
    for(int i=2;i<=N;++i) {
        int x = 1;
        for(int j=0;j<m[p[i]].size();++j) {
            int y = m[p[i]][j];
            if(y==i) continue;
            x = (1LL*x*(d[y]+1)) % MOD;
        }
        u[i] = (1LL*u[p[i]]*x  + 1) %MOD;
    }

    for(int i=1;i<=N;++i) {
        int x = (1LL*d[i]*u[i]) % MOD;
        printf("%d ",x);
    }
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#define MOD 1000000007
using namespace std;
int N,M,p[200100],d[200100],u[200100];
vector<int> m[200100];

int pw(int x, int y) {
    if(y==0) {
        return 1;
    }
    int z = pw(x, y/2);
     z = (1LL*z*z) % MOD;
    if(y%2) {
        z = (1LL*z*x) % MOD;
    }
    return z;
}

int inv(int x) {
    return pw(x, MOD-2);
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif
    scanf("%d",&N);
    p[1] = 0;
    for(int i=2;i<=N;++i) {
        scanf("%d",&p[i]);
    }
    for(int i=1;i<=N;++i) {
        d[i] = 1;
        u[i] = 1;
        m[p[i]].push_back(i);
    }

    for(int i=N;i>=1;--i) {
        d[p[i]] = (1LL*d[p[i]]*(d[i] + 1)) % MOD;
    }
    for(int i=2;i<=N;++i) {
        int x = 1;
        if((d[i]+1)%MOD == 0) {
            for(int j=0;j<m[p[i]].size();++j) {
                int y = m[p[i]][j];
                if(y==i) continue;
                x = (1LL*x*(d[y]+1)) % MOD;
            }
        } else {
            x = (1LL*d[p[i]]*inv(d[i]+1)) % MOD;
        }
        u[i] = (1LL*u[p[i]]*x+1) %MOD;
    }

    for(int i=1;i<=N;++i) {
        int x = (1LL*d[i]*u[i]) % MOD;
        printf("%d ",x);
    }
	return 0;
}


#include<stdio.h>
#include<iostream>
#define MOD 1000000007
using namespace std;
int N,M,p[200100],d[200100],u[200100];

int pw(int x, int y) {
    if(y==0) {
        return 1;
    }
    int z = pw(x, y/2);
     z = (1LL*z*z) % MOD;
    if(y%2) {
        z = (1LL*z*x) % MOD;
    }
    return z;
}

int inv(int x) {
    return pw(x, MOD-2);
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif
    scanf("%d",&N);
    for(int i=2;i<=N;++i) {
        scanf("%d",&p[i]);
    }
    for(int i=1;i<=N;++i) {
        d[i] = 1;
        u[i] = 1;
    }

    for(int i=N;i>=1;--i) {
        d[p[i]] = (1LL*d[p[i]]*(d[i] + 1)) % MOD;
    }
    for(int i=2;i<=N;++i) {
        int x = (1LL*d[p[i]] * inv((d[i]+1))) % MOD;
        u[i] = (1LL*u[p[i]]*x  + 1) %MOD;
    }

    for(int i=1;i<=N;++i) {
        int x = (1LL*d[i]*u[i]) % MOD;
        printf("%d ",x);
    }
	return 0;
}


#include<stdio.h>
#include<iostream>
#define MOD 1000000007
using namespace std;
int N,M,p[200100],d[200100],u[200100];

int pw(int x, int y) {
    if(y==0) {
        return 1;
    }
    int z = pw(x, y/2);
     z = (1LL*z*z) % MOD;
    if(y%2) {
        z = (1LL*z*x) % MOD;
    }
    return z;
}

int inv(int x) {
    return pw(x, MOD-2);
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif
    scanf("%d",&N);
    for(int i=2;i<=N;++i) {
        scanf("%d",&p[i]);
    }
    for(int i=1;i<=N;++i) {
        d[i] = 1;
        u[i] = 1;
    }

    for(int i=N;i>=1;--i) {
        d[p[i]] = (d[p[i]]*(d[i] + 1)) % MOD;
    }
    for(int i=2;i<=N;++i) {
        int x = (1LL*d[p[i]] * inv((d[i]+1))) % MOD;
        u[i] = (1LL*u[p[i]]*x  + 1) %MOD;
    }

    for(int i=1;i<=N;++i) {
        int x = (1LL*d[i]*u[i]) % MOD;
        printf("%d ",x);
    }
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#define MOD 1000000007
using namespace std;
int N,M,p[200100],d[200100],u[200100];
vector<int> m[200100];

int pw(int x, int y) {
    if(y==0) {
        return 1;
    }
    int z = pw(x, y/2);
     z = (1LL*z*z) % MOD;
    if(y%2) {
        z = (1LL*z*x) % MOD;
    }
    return z;
}

int inv(int x) {
    return pw(x, MOD-2);
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif
    scanf("%d",&N);
    p[1] = 0;
    for(int i=2;i<=N;++i) {
        scanf("%d",&p[i]);
    }
    for(int i=1;i<=N;++i) {
        d[i] = 1;
        u[i] = 1;
        m[p[i]].push_back(i);
    }

    for(int i=N;i>=1;--i) {
        d[p[i]] = (1LL*d[p[i]]*(d[i] + 1)) % MOD;
    }
    for(int i=2;i<=N;++i) {
        int x = 1;
        if((d[i]+1)%MOD == 0) {
            for(int j=0;j<m[p[i]].size();++j) {
                int y = m[p[i]][j];
                if(y==i) continue;
                x = (1LL*x*(d[y]+1)) % MOD;
            }
        } else {
            x = (1LL*d[p[i]]*inv(d[i]+1));
        }
        u[i] = (1LL*u[p[i]]*x+1) %MOD;
    }

    for(int i=1;i<=N;++i) {
        int x = (1LL*d[i]*u[i]) % MOD;
        printf("%d ",x);
    }
	return 0;
}


#include<stdio.h>
#include<iostream>
#define MOD 1000000007
using namespace std;
int N,M,p[200100],d[200100],u[200100];

int pw(int x, int y) {
    if(y==0) {
        return 1;
    }
    int z = pw(x, y/2);
     z = (1LL*z*z) % MOD;
    if(y%2) {
        z = (1LL*z*x) % MOD;
    }
    return z;
}

int inv(int x) {
    return pw(x, MOD-2);
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif
    scanf("%d",&N);
    for(int i=2;i<=N;++i) {
        scanf("%d",&p[i]);
    }
    for(int i=1;i<=N;++i) {
        d[i] = 1;
        u[i] = 1;
    }

    for(int i=N;i>=1;--i) {
        d[p[i]] = (d[p[i]]*(d[i] + 1)) % MOD;
    }
    for(int i=2;i<=N;++i) {
        int x = (1LL*d[p[i]] * inv((d[i]+1))) % MOD;
        u[i] = (1 + u[p[i]]*x ) %MOD;
    }

    for(int i=1;i<=N;++i) {
        int x = (1LL*d[i]*u[i]) % MOD;
        printf("%d ",x);
    }
	return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);
ll d, x, y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        ll temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}

ll modInverse(ll A, ll M)
{
    extendedEuclid(A,M);
    return (x%M+M)%M;    //x may be negative
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(x % 2 ==1)
            result=(result %M* x%M)%M;
        x=(x%M*x)%M;
        n=n/2;
    }
    return result;
}

/*ll modInverse(ll A)
{
    return modularExponentiation(A,MOD-1,MOD);
}
*/

void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";
        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        /*if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }*/

    ll t_node;
    if(two[node]==1)
                    {
                        t_node=(dp[node]%MOD+2)%MOD;
                    }
                    else
                    {
                        t_node=(dp[node]%MOD+1)%MOD;
                    }

        if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
        //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";
       ll b=modInverse(t_node,MOD);

       //cout<<"\n tnode "<<b;
       dp[parent]=(b*dp[parent]%MOD)%MOD;
       //dp[parent]=(dp[parent]/t_node)%MOD;
       //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";
       }

    if(two[node]==1)
    {
        dp[node]=1;
    }

    if(two[parent]==1)
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+2)%MOD)%MOD;
            }
            else
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+1)%MOD)%MOD;
            }
    /*for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
    }*/
        cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
            dp[node]=temp_node;
            if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==1)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);
ll d, x, y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        ll temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}

ll modInverse(ll A, ll M)
{
    extendedEuclid(A,M);
    return (x%M+M)%M;    //x may be negative
}

void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";
        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        /*if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }*/

    ll t_node;
    if(two[node]==1)
    {
        t_node=(dp[node]%MOD+2)%MOD;
    }
    else
    {
        t_node=(dp[node]%MOD+1)%MOD;
    }

        if(two[parent]==1)
        {
           dp[parent]=0;

        }
        else
        {
        //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";
        if(t_node%MOD==0)
        {
            dp[parent]=0;
        }
        else{
       ll b=modInverse(t_node,MOD);

       //cout<<"\n tnode "<<b;
       dp[parent]=(b%MOD*dp[parent]%MOD)%MOD;}
       //dp[parent]=(dp[parent]/t_node)%MOD;
       //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";
       }

    if(two[node]==1)
    {
        dp[node]=1;
    }

    if(two[parent]==1)
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+2)%MOD)%MOD;
            }
            else
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+1)%MOD)%MOD;
            }
    /*for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
    }*/
        cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
            dp[node]=temp_node;
            if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==1)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);
void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";

        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }

    dp[node]=1;

    for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
    }
    if(node!=2)
    cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
                dp[node]=temp_node;
                if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==1)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(x % 2 ==1)
            result=(result %M* x%M)%M;
        x=(x%M*x)%M;
        n=n/2;
    }
    return result;
}

ll modInverse(ll A)
{
    return modularExponentiation(A,MOD-2,MOD);
}

void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";

        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        /*if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }*/

    ll t_node;
    if(two[node]==1)
                    {
                         t_node=(dp[node]+2)%MOD;
                    }
                    else
                    {
                        t_node=(dp[node]+1)%MOD;
                    }

if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {}
            //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";
       //ll b=modInverse(t_node);
       //dp[parent]=(b%MOD*dp[parent]+)%MOD;
       dp[parent]=(dp[parent]/t_node)%MOD;
       //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";}

    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=1;
    }

    if(two[parent]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[parent]+2)%MOD)%MOD;
            }
            else
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+1)%MOD)%MOD;
             }
    /*for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
    }*/
    if(node!=2)
    cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
                dp[node]=temp_node;
                if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==1)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);
void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";

        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }

    dp[node]=1;

    for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
    }
    if(node!=2)
    cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
                dp[node]=temp_node;
                if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==1)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);
ll d, x, y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        ll temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}

ll modInverse(ll A, ll M)
{
    extendedEuclid(A,M);
    return (x%M+M)%M;    //x may be negative
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(x % 2 ==1)
            result=(result %M* x%M)%M;
        x=(x%M*x)%M;
        n=n/2;
    }
    return result;
}

/*ll modInverse(ll A)
{
    return modularExponentiation(A,MOD-1,MOD);
}
*/

void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";

        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        /*if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }*/

    ll t_node;
    if(two[node]==1)
                    {
                         t_node=(dp[node]+2)%MOD;
                    }
                    else
                    {
                        t_node=(dp[node]+1)%MOD;
                    }

if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
        //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";
       ll b=modInverse(t_node,MOD);

       //cout<<"\n tnode "<<b;
       dp[parent]=(b%MOD*dp[parent]%MOD)%MOD;
       //dp[parent]=(dp[parent]/t_node)%MOD;
       //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";
       }

    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=1;
    }

    if(two[parent]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[parent]+2)%MOD)%MOD;
            }
            else
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+1)%MOD)%MOD;
             }
    /*for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
    }*/
    if(node!=2)
    cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
                dp[node]=temp_node;
                if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==1)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);
void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";

        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                }
    }

    dp[node]=1;

    for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
    }
    if(node!=2)
    cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
                dp[node]=temp_node;
                if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==2)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);
ll d, x, y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        ll temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}

ll modInverse(ll A, ll M)
{
    extendedEuclid(A,M);
    return (x%M+M)%M;    //x may be negative
}

void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";
        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        /*if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }*/

    ll t_node;
    if(two[node]==1)
    {
        t_node=(dp[node]%MOD+2)%MOD;
    }
    else
    {
        t_node=(dp[node]%MOD+1)%MOD;
    }

        if(two[parent]==1)
        {
           dp[parent]=0;

        }
        else
        {
        //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";
        if(t_node%MOD==0)
        {
            dp[parent]=1;
            for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }
        }
        else{
       ll b=modInverse(t_node,MOD);

       //cout<<"\n tnode "<<b;
       dp[parent]=(b%MOD*dp[parent]%MOD)%MOD;}
       //dp[parent]=(dp[parent]/t_node)%MOD;
       //cout<<"\n node "<<node<<" dp[node]= "<<dp[node]<<" "<<parent<<" "<<dp[parent]<<"\n";
       }

    if(two[node]==1)
    {
        dp[node]=1;
    }

    if(two[parent]==1)
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+2)%MOD)%MOD;
            }
            else
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+1)%MOD)%MOD;
            }
    /*for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
    }*/
        cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
            dp[node]=temp_node;
            if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==1)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);
void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";

        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }

    if(dp[node]==0)
    dp[node]=1;

    if(two[parent]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[parent]+2)%MOD)%MOD;
            }
            else
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+1)%MOD)%MOD;
             }
    /*for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
    }*/
    if(node!=2)
    cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
                dp[node]=temp_node;
                if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==1)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<iostream>
#define ll long long int
#include<string>
using namespace std;
#include<vector>
#include<set>
#include<algorithm>
#define MOD 1000000007
vector<ll> p(1000000),dp(1000000),cou(1000000),two(1000000);
vector<vector<ll> > adj(1000000);
void dfs(ll node , ll parent)
{
    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=0;
        return ;
    }
    else
    {
       // cout<<" +++ ";

        dp[node]=1;
    }
    ll i;
   // cout<<"node "<<node<<" "<<adj[node].size()<<" :size \n";
    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            dfs(adj[node][i],node);
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
            //cout<<"\n "<<i<<" "<<dp[node]<<";;;";
        }
    }
    return ;
}

void tdfs(ll node,ll parent)
{

    ll i,j,temp_node,temp_parent;
    if(parent!=-1)
    temp_parent=dp[parent];
     temp_node=dp[node];

    if(parent!=-1)
    {

        if(adj[parent].size()==1&&adj[parent][0]==node)
        {
           dp[parent]=0;

        }
        else
        {
       // cout<<" +++ ";

          dp[parent]=1;
       }

    for(j=0;j<adj[parent].size();j=j+1)
    {
                if(adj[parent][j]!=node)
                {
                    if(two[adj[parent][j]]==1)
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+2)%MOD)%MOD;
                    }
                    else
                    {
                        dp[parent]=(dp[parent]%MOD*(dp[adj[parent][j]]+1)%MOD)%MOD;
                    }
                }
    }

    if(adj[node].size()==1&&adj[node][0]==parent)
    {
        dp[node]=1;
    }

    if(two[parent]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[parent]+2)%MOD)%MOD;
            }
            else
            {
                 dp[node]=(dp[node]%MOD*(dp[parent]+1)%MOD)%MOD;
             }
    /*for(i=0;i<adj[node].size();i=i+1)
    {
            if(two[adj[node][i]]==1)
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+2)%MOD)%MOD;
            }
            else
            {
                dp[node]=(dp[node]%MOD*(dp[adj[node][i]]+1)%MOD)%MOD;
            }
    }*/
    if(node!=2)
    cou[node]=dp[node];
    }

    for(i=0;i<adj[node].size();i=i+1)
    {
        if(adj[node][i]!=parent)
        {
            tdfs(adj[node][i],node);

        }
    }
                dp[node]=temp_node;
                if(parent!=-1)
            dp[parent]=temp_parent;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x;
    cin>>n;
    for(i=2;i<=n;i=i+1)
    {
        cin>>x;
        adj[i].push_back(x);
        adj[x].push_back(i);
    }
    //cout<<adj[1][0]<<" "<<adj[1][1]<<"\n";
    for(i=1;i<=n;i=i+1)
    {
        //cout<<"node "<<i<<" "<<adj[i].size()<<" :size \n";
        if(adj[i].size()==1)
        two[i]=1;
    }
    dfs(2,-1);
    cou[2]=dp[2];
    //cout<<cou[2]<<"\n";
    tdfs(2,-1);
    for(i=1;i<=n;i=i+1)
    cout<<cou[i]<<" ";
    cout<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 200005

vector <int> v[N];
const int mod = 1e9 + 7;
int par[N], n, a[N], b[N], c[N];

int pow(int x, int k) {
	if(k == 0) return 1;
	if(k % 2 == 1) return 1ll * x * pow(x, k - 1) % mod;
	int y = pow(x, k / 2);
	return 1ll * y * y % mod;
}

void dfs(int k) {
	a[k] = 1;
	for(int i = 0; i < v[k].size(); i ++) {
		dfs(v[k][i]);
		a[k] = 1ll * a[k] * (1 + a[v[k][i]]) % mod;
	}
}

void dfs1(int k) {
	b[k] = (1ll * b[par[k]] * c[k] % mod + 1) * a[k] % mod;
	for(int i = 0; i < v[k].size(); i ++) dfs1(v[k][i]);
}

int main() {
	int i, j;
	scanf("%d", &n);
	for(i = 2; i <= n; i ++){
		scanf("%d", par + i);
		v[par[i]].push_back(i);
	}
	dfs(1);
	for(i = 1; i <= n; i ++) c[i] = pow(1 + a[i], mod - 2);
	dfs1(1);
	for(i = 1; i <= n; i ++) printf("%d ", b[i]);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200005

vector <int> v[N];
const int mod = 1e9 + 7;
int par[N], n, a[N], b[N], c[N];

int pow(int x, int k) {
	if(k == 0) return 1;
	if(k % 2 == 1) return (int)(1ll * x * pow(x, k - 1) % mod);
	int y = pow(x, k / 2);
	return (int)(1ll * y * y % mod);
}

void dfs(int k) {
	a[k] = 1;
	for(int i = 0; i < v[k].size(); i ++) {
		dfs(v[k][i]);
		a[k] = (int)(1ll * a[k] * (1 + a[v[k][i]]) % mod);
	}
}

void dfs1(int k) {
	b[k] = (int)(1ll * (1ll * b[par[k]] * c[k] % mod + 1) * a[k] % mod);
	for(int i = 0; i < v[k].size(); i ++) dfs1(v[k][i]);
}

int main() {
	int i, j;
	scanf("%d", &n);
	for(i = 2; i <= n; i ++){
		scanf("%d", par + i);
		v[par[i]].push_back(i);
	}
	dfs(1);
	for(i = 1; i <= n; i ++) c[i] = pow(1 + a[i], mod - 2);
	dfs1(1);
	for(i = 1; i <= n; i ++) printf("%d ", b[i]);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200005

vector <int> v[N];
vector <int> vv[N];
const int mod = 1e9 + 7;
int par[N], n, a[N], b[N], d[N];

int pow(int x, int k) {
	if(k == 0) return 1;
	if(k % 2 == 1) return 1ll * x * pow(x, k - 1) % mod;
	int y = pow(x, k / 2);
	return 1ll * y * y % mod;
}

void dfs(int k) {
	int i, j, rlt = 1, sz = v[k].size();
	for(i = 0; i < sz; i ++) dfs(v[k][i]);
	for(i = 0; i < sz; i ++) if(a[v[k][i]] == mod - 1) break;
	if(i < sz) {
		for(j = 0; j < sz; j ++) if(i != j) rlt = 1ll * rlt * (1 + a[v[k][j]]) % mod;
		for(j = 0; j < sz; j ++) {
			if(i == j) vv[k][j] *= rlt;
			else vv[k][j] *= 0;
		}
		a[k] = 0;
	}
	else {
		for(j = 0; j < sz; j ++) rlt = 1ll * rlt * (1 + a[v[k][j]]) % mod;
		for(j = 0; j < sz; j ++) {
			vv[k][j] *= 1ll * rlt * pow(1 + a[v[k][j]], mod - 2) % mod;
		}
		a[k] = rlt;
	}
}

void dfs2(int k, int x) {
	d[k] = 1ll * (1 + d[par[k]]) * vv[par[k]][x] % mod;
	b[k] = 1ll * (1 + d[k]) * a[k] % mod;
	for(int i = 0; i < v[k].size(); i ++) dfs2(v[k][i], i);
}

int main() {
	int i, j;
	scanf("%d", &n);
	for(i = 2; i <= n; i ++){
		scanf("%d", par + i);
		v[par[i]].push_back(i);
		vv[par[i]].push_back(1);
	}
	vv[0].push_back(0);
	dfs(1);
	dfs2(1, 0);
	for(i = 1; i <= n; i ++) printf("%d ", b[i]);
}


#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define N 200010

int n, pa[N], dp[N], ans[N], rev[N], cross[N];
vector <int> V[N];

int rever(int u, int v = mod) {
	if (u == 1) return 1;
	int q = v / u;
	int r = v % u;
	int s = rever(r, u);
	int t = (1LL * r * s - 1) / u;
	return v - (1LL * q * s % v + t) % v;
}

void dfs(int v) {
	dp[v] = 1;
    for (int i = 0; i < V[v].size(); i ++) {
		int vv = V[v][i];
		dfs(vv);
		dp[v] = 1LL * (dp[vv] + 1) * dp[v] % mod;
    }
}

void calc(int v) {
	for (int i = 0; i < V[v].size(); i ++) {
		int vv = V[v][i];
		cross[vv] = (1LL * cross[v] * rev[vv] + 1)% mod;
		calc(vv);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; i ++) {
		scanf("%d", &pa[i]);
		V[pa[i]].push_back(i);
	}
	dfs(1);
	memset(rev, -1, sizeof rev);
	for (int i = 2; i <= n; i ++) {
		if (rev[i] >= 0) continue;
		else {
			int x = pa[i];
            if (dp[i] + 1 != mod) rev[i] = 1LL * dp[x] * rever(dp[i] + 1) % mod;
            else {
				rev[i] = 1;
				for (int j = 0; j < V[x].size(); j ++) {
					int y = V[x][j];
					if (x != y) rev[i] = 1LL * (dp[y] + 1) * rev[i] % mod;
				}
				for (int j = 0; j < V[x].size(); j ++) if (i != V[x][j]) rev[V[x][j]] = 0;
            }
		}
	}
	cross[1] = 1;
	calc(1);
	for (int i = 1; i <= n; i ++) ans[i] = 1LL * cross[i] * dp[i] % mod;
	for (int i = 1; i <= n; i ++) printf("%d ", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define N 200010

int n, pa[N], dp[N], ans[N], rev[N], cross[N];
vector <int> V[N];

int rever(int u, int v = mod) {
	if (u == 1) return 1;
	int q = v / u;
	int r = v % u;
	int s = rever(r, u);
	int t = (1LL * r * s - 1) / u;
	return v - (1LL * q * s % v + t) % v;
}

void dfs(int v) {
	dp[v] = 1;
    for (int i = 0; i < V[v].size(); i ++) {
		int vv = V[v][i];
		dfs(vv);
		dp[v] = 1LL * (dp[vv] + 1) * dp[v] % mod;
    }
}

void calc(int v) {
	for (int i = 0; i < V[v].size(); i ++) {
		int vv = V[v][i];
		cross[vv] = (1LL * cross[v] * rev[vv] + 1)% mod;
		calc(vv);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; i ++) {
		scanf("%d", &pa[i]);
		V[pa[i]].push_back(i);
	}
	dfs(1);
	memset(rev, -1, sizeof rev);
	for (int i = 2; i <= n; i ++) {
		if (rev[i] >= 0) continue;
		else {
			rev[i] = 1;
			int x = pa[i];
            if (dp[i] + 1 != mod) rev[i] = 1LL * dp[x] * rever(dp[i] + 1) % mod;
            else {
				rev[i] = 1;
				for (int j = 0; j < V[x].size(); j ++) {
					int y = V[x][j];
					if (i != y) rev[i] = 1LL * (dp[y] + 1) * rev[i] % mod;
				}
				for (int j = 0; j < V[x].size(); j ++) if (i != V[x][j]) rev[V[x][j]] = 0;
            }
		}
	}
	cross[1] = 1;
	calc(1);
	for (int i = 1; i <= n; i ++) ans[i] = 1LL * cross[i] * dp[i] % mod;
	for (int i = 1; i <= n; i ++) printf("%d ", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200005

vector <int> v[N];
const int mod = 1e9 + 7;
int par[N], n, a[N], b[N], c[N];

int pow(int x, int k) {
	if(x == 0) return 0;
	if(k == 0) return 1;
	if(k % 2 == 1) return (int)(1ll * x * pow(x, k - 1) % mod);
	int y = pow(x, k / 2);
	return (int)(1ll * y * y % mod);
}

void dfs(int k) {
	a[k] = 1;
	for(int i = 0; i < v[k].size(); i ++) {
		dfs(v[k][i]);
		a[k] = (int)(1ll * a[k] * (1 + a[v[k][i]]) % mod);
	}
}

void dfs1(int k) {
	b[k] = (int)(1ll * (1ll * b[par[k]] * c[k] % mod + 1) * a[k] % mod);
	for(int i = 0; i < v[k].size(); i ++) dfs1(v[k][i]);
}

int main() {
	int i, j;
	scanf("%d", &n);
	for(i = 2; i <= n; i ++){
		scanf("%d", par + i);
		v[par[i]].push_back(i);
	}
	dfs(1);
	for(i = 1; i <= n; i ++) c[i] = pow((1 + a[i]) % mod, mod - 2);
	dfs1(1);
	for(i = 1; i <= n; i ++) printf("%d ", b[i]);
}