Problem:
Score : 600 points

Problem Statement

We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i.
For each k=1, ..., N, solve the problem below:

Consider writing a number on each vertex in the tree in the following manner:

First, write 1 on Vertex k.

Then, for each of the numbers 2, ..., N in this order, write the number on the vertex chosen as follows:

Choose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.

Find the number of ways in which we can write the numbers on the vertices, modulo (10^9+7).

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq a_i,b_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

For each k=1, 2, ..., N in this order, print a line containing the answer to the problem.

Sample Input 1

3
1 2
1 3

Sample Output 1

2
1
1

The graph in this input is as follows:

For k=1, there are two ways in which we can write the numbers on the vertices, as follows:

Writing 1, 2, 3 on Vertex 1, 2, 3, respectively

Writing 1, 3, 2 on Vertex 1, 2, 3, respectively

Sample Input 2

2
1 2

Sample Output 2

1
1

The graph in this input is as follows:

Sample Input 3

5
1 2
2 3
3 4
3 5

Sample Output 3

2
8
12
3
3

The graph in this input is as follows:

Sample Input 4

8
1 2
2 3
3 4
3 5
3 6
6 7
6 8

Sample Output 4

40
280
840
120
120
504
72
72

The graph in this input is as follows:

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.StringTokenizer;

class Main {

	public static final int mod = (int)1e9+7;
	public static final int max = (int)5e5;
	public static long[] facts;
	public static long[] invfacts;
	public static void preCompute() {
		facts = new long[max];
		invfacts = new long[max];
		facts[1] = invfacts[1] = facts[0] = invfacts[0] = 1L;
		for(int i = 2; i < max; i++) {
			facts[i] = (facts[i - 1] * (long)i)%mod;
			invfacts[i] = (invfacts[i - 1] * (long)ModInverse(i, mod))%mod;
		}
	}
	public static long nCr(int n, int r) {
		long ans = (facts[n] * invfacts[r])%mod;
		ans *= invfacts[n - r];
		ans %= mod;
		return ans;
	}
	
	public static LinkedList<Integer>[] adj;
	
	public static long[] dp1;
	public static long[] dp2;
	
	public static void dfs1(int curr, int pr) {
////		if(adj[curr].size() == 1) {
//			dp1[curr] = 1;
//			dp2[curr] = 1;
//			return;
//		}
		long ans = 1;
		long size = 0;
		for(Integer x : adj[curr]) {
			if(x == pr) continue;
			dfs1(x, curr);
			size += dp1[x];
			long size2 = dp1[x];
			ans *= dp2[x];
			ans %= mod;
			ans *= nCr((int)size, (int)size2);
			ans %= mod;
		}
		dp2[curr] = ans;
		dp1[curr] = size + 1L;
	}
	
	public static void dfs2(int curr, int pr) {
		if(curr == 0) {
			for(Integer x : adj[curr]) {
				dfs2(x, curr);
			}
		}else {
			long size_pr = dp1[pr] - dp1[curr] - 1;
			long size_over = dp1[pr] - 1;
			long ans_pr = dp2[pr];
			ans_pr = ans_pr * ModInverse(dp2[curr], mod);
			ans_pr %= mod;
			ans_pr = ans_pr * ModInverse(nCr((int)size_over, (int)size_pr), mod);
			ans_pr %= mod;
			long my_ans = dp2[curr];
			my_ans = my_ans * ans_pr;
			my_ans %= mod;
			my_ans *= (nCr((int)size_over, (int)size_pr+1)% mod);
			my_ans %= mod;
			dp1[curr] = size_over + 1;
			dp2[curr] = my_ans;
			for(Integer x : adj[curr]) {
				if(x == pr) continue;
				dfs2(x, curr);
			}
		}
	}
 	
	public static void solve() {
		preCompute();
		int n = s.nextInt();
		adj = new LinkedList[n];
		for(int i = 0; i < n; i++) {
			adj[i] = new LinkedList<Integer>();
		}
		for(int i = 0; i < n - 1; i++) {
			int a = s.nextInt() - 1;
			int b = s.nextInt() - 1;
			adj[a].add(b);
			adj[b].add(a);
		}
		dp1 = new long[n]; dp2 = new long[n];
		dfs1(0, 0);
		dfs2(0, 0);
		for(int i = 0; i < n; i++) {
			out.println(dp2[i]);
		}
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}
	
	public static class Triplet {
		long gcd;
		long x;
		long y;

		Triplet(long gcd, long x, long y) {
			this.gcd = gcd;
			this.x = x;
			this.y = y;
		}
	}

	public static Triplet ExtendedEuclideanAlgo(long a, long b) {
		if (a == 0) {
			return new Triplet(b, 0, 1);
		}
		Triplet ans = ExtendedEuclideanAlgo(b % a, a);
		long x = ans.y - (b / a) * ans.x;
		long y = ans.x;
		return new Triplet(ans.gcd, x, y);
	}

	public static long ModInverse(long a, long m) {
		Triplet ans = ExtendedEuclideanAlgo(a, m);
		if (ans.gcd != 1) {
			//System.out.println("Multiplicative inverse doesnot exist");
			return -1;
		} else {
			//m is added to handle negative x
			long result = (ans.x % m + m) % m;
			return result;
		}
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}