#pragma GCC optimize("Ofast")
#pragma GCC target ("avx")
#pragma GCC optimize("unroll-loops")

#include <stdio.h>
#include <utility>

// 入力
constexpr unsigned int MAX_INPUT_SIZE = 3'000'000; //'
char Input[MAX_INPUT_SIZE];
char* input = Input;
char* output = Input;
inline unsigned int get(void){
    unsigned long long int res = *(unsigned long long int*)input; // リトルエンディアン
    const unsigned int a = __builtin_ctzll((res & 0x1010101010101010) ^ 0x1010101010101010); // 左にビット寄せ
    input += (a + 4) >> 3;
    res = (res << (68 - a)) & 0x0f0f0f0f0f0f0f0f;
    res = (res * 10 + (res >> 8)) & 0x00ff00ff00ff00ff;
    res = (res * 100 + (res >> 16)) & 0x0000ffff0000ffff;
    res = (res * 10000 + (res >> 32)) & 0x00000000ffffffff;
    return res;
}
// 出力

constexpr unsigned int digit = 5;
constexpr unsigned int MAX_D_SIZE = 100'000; //'
struct NoName{
    char S[MAX_D_SIZE][digit + 1];
    char T[MAX_D_SIZE][digit + 1];
    constexpr NoName(void): S(), T(){
        for(unsigned int i = 0; i < MAX_D_SIZE; ++i){
            unsigned int t = i;
            char* ptr = S[i];
            while(t){ *(ptr++) = '0' ^ (t % 10); t /= 10; }
            for(unsigned int j = 0, j2 = digit - 1; j < digit; ++j, --j2){
                T[i][j2] = S[i][j] ? S[i][j] : '0';
            }
            --ptr; char* ptr2 = S[i];
            while(ptr2 < ptr){
                const char c = *ptr; 
                *(ptr--) = *ptr2; *(ptr2++) = c;
            }
        }
    }
};
constexpr NoName Da;

inline void writeBuffer(unsigned long long int n){

    if(n < MAX_D_SIZE){
        const char* ptr = Da.S[n];
        while(*ptr) *(output++) = *(ptr++);
    }
    else{
        const char* ptr1 = Da.T[n % MAX_D_SIZE];
        const char* ptr2 = Da.S[n / MAX_D_SIZE];
        while(*ptr2) *(output++) = *(ptr2++);
        while(*ptr1) *(output++) = *(ptr1++);
    }    
    *(output++) = '\n';
}

// 制約
constexpr unsigned int MAX_N = 200'000; //'
constexpr unsigned int mod = 1'000'000'007; //'

// 階乗計算
template <const unsigned int M> struct shuumai {
public:
    unsigned long long int P[M + 1];
    unsigned long long int Inv[M + 1];
    unsigned long long int inv[M + 1];
    constexpr shuumai(void):P(), Inv(), inv(){
        P[0] = 1; P[1] = 1;
        for(unsigned int x = 1, y = 2; x < M; ++x, ++y) P[y] = (P[x] * y) % mod;
        Inv[M] = inverse(P[M]);
        for(unsigned int x = M, y = M - 1; x ; --x, --y){
            Inv[y] = (Inv[x] * x) % mod;
            inv[x] = (P[y] * Inv[x]) % mod;
        }
        inv[0] = 1;
    }
    constexpr unsigned int inverse(unsigned int a) const noexcept {
        unsigned int b = mod;
                 int u = 1, v = 0;
        while (b) {
            unsigned int t = a / b; 
            a -= t * b; { const unsigned int tmp = a; a = b; b = tmp; }
            u -= t * v; { const unsigned int tmp = u; u = v; v = tmp; }
        }
        if(u < 0) u += mod;
        return u;
    }
};
constexpr shuumai<MAX_N> karashi;

// リスト
struct Node{
    unsigned int vertex;
    unsigned int next;
};
Node node[2 * MAX_N];
unsigned int begin[MAX_N];
unsigned int end = 1;
inline void append(const unsigned int u, const unsigned v){
    node[end] = {v, begin[u]}; begin[u] = end++;
    node[end] = {u, begin[v]}; begin[v] = end++;
}

// 擬似stack
unsigned int Stack[MAX_N];
unsigned int index_stack = 0;

inline void push(const unsigned int value){ Stack[index_stack++] = value; }
inline unsigned int top(void){ return Stack[--index_stack];}
inline bool exist(void){ return index_stack; }

// 
bool visited[MAX_N];
unsigned int parent[MAX_N];
unsigned int order[MAX_N];
unsigned int index_order = 0;

unsigned int subTree[MAX_N];
unsigned long long int dp[MAX_N];

int main(void){
    fread_unlocked(Input, sizeof(char), MAX_INPUT_SIZE, stdin);
    const unsigned int n = get();

    for(unsigned int _ = 1; _ < n; ++_) append(get() - 1, get() - 1);
    // DFSの順序決め
    push(0); visited[0] = true; order[index_order++] = 0;
    while(exist()){
        const unsigned int v = top();
        for(unsigned int idx = begin[v]; idx ; idx = node[idx].next){
            const unsigned int nv = node[idx].vertex;
            if(not visited[nv]){ 
                visited[nv] = true; parent[nv] = v; 
                order[index_order++] = nv; push(nv);  
            }
        }
    }

    for(unsigned int i = 0; i < n; ++i) dp[i] = 1;
    // 根からボトムアップにdp値を計算
    for(unsigned int i = n - 1; i ; --i){
        const unsigned int v = order[i];
        const unsigned int nv = parent[v];
        dp[v] = dp[v] * karashi.P[subTree[v]++] % mod;
        dp[nv] = dp[nv] * (dp[v] * karashi.Inv[subTree[v]] % mod) % mod;
        subTree[nv] += subTree[v];
    }

    {
        dp[0] = dp[0] * karashi.P[subTree[0]++] % mod;
    }


    for(unsigned int i = 1; i < n; ++i){
        const unsigned int v = order[i];
        const unsigned int nv = parent[v];
        dp[v] = dp[nv] * (subTree[v] * karashi.inv[n - subTree[v]] % mod) % mod;
    }

    // 出力
    for(unsigned int i = 0; i < n; ++i) writeBuffer(dp[i]);
    *output = '\0';
    fwrite_unlocked(Input, sizeof(char), output - Input, stdout);
    return 0;
}

Measured memory_bytes: 13568