Problem: Alice and Bob are playing a game. They have a tree consisting of n vertices. Initially, Bob has k chips, the i-th chip is located in the vertex a_i (all these vertices are unique). Before the game starts, Alice will place a chip into one of the vertices of the tree.

The game consists of turns. Each turn, the following events happen (sequentially, exactly in the following order):

  1. Alice either moves her chip to an adjacent vertex or doesn't move it; 
  2. for each Bob's chip, he either moves it to an adjacent vertex or doesn't move it. Note that this choice is done independently for each chip. 



The game ends when Alice's chip shares the same vertex with one (or multiple) of Bob's chips. Note that Bob's chips may share the same vertex, even though they are in different vertices at the beginning of the game.

Alice wants to maximize the number of turns, Bob wants to minimize it. If the game ends in the middle of some turn (Alice moves her chip to a vertex that contains one or multiple Bob's chips), this turn is counted.

For each vertex, calculate the number of turns the game will last if Alice places her chip in that vertex.

Input

The first line contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of vertices in the tree.

Then n - 1 lines follow, each line contains two integers u_i, v_i (1 ≤ u_i, v_i ≤ n; u_i ≠ v_i) that denote the endpoints of an edge. These edges form a tree.

The next line contains one integer k (1 ≤ k ≤ n - 1) — the number of Bob's chips.

The last line contains k integers a_1, a_2, ..., a_k (1 ≤ a_i ≤ n; a_i ≠ a_j if i ≠ j) — the vertices where the Bob's chips are initially placed.

Output

Print n integers. The i-th of them should be equal to the number of turns the game will last if Alice initially places her chip in the vertex i. If one of Bob's chips is already placed in vertex i, then the answer for vertex i is 0.

Examples

Input


5
2 4
3 1
3 4
3 5
2
4 5


Output


2 1 2 0 0


Input


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


Output


3 0 0 3 1 2 3 0


Input


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


Output


0 2 2 2 2 0 2 2 0 0

Solution (in CPP):

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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}


#define MAX 200010
#define LOG 20

namespace LCA{
  int sum[MAX] ; int st[MAX],en[MAX],lg[MAX],par[MAX],a[MAX],
  id[MAX],dp[LOG][MAX] ;
  vector <int> weight[MAX] , g[MAX]; int n , r , Time , cur ;
  void init(int nodes, int root){
    n = nodes, r = root, lg[0] = lg[1] = 0;
    for(int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
    for(int i=0;i<= n;i++) g[i].clear(), weight[i].clear();
  }
  void addEdge(int u, int v, int w){
    g[u].push_back(v), weight[u].push_back(w);
    g[v].push_back(u), weight[v].push_back(w);
  }
  int lca(int u, int v){
    if( en[u] > en[v] )swap(u,v) ;
    if( st[v] <= st[u] && en[u] <= en[v] ) return v ;
    int l = lg[id[v] - id[u] + 1] ;
    int p1 = id[u] , p2 = id[v] - (1<<l) + 1 ;
    if(sum[dp[l][p1]]<sum[dp[l][p2]]) return par[dp[l][p1]] ;
    else return par[ dp[l][p2] ] ;
  }
  int dis( int u ,int v ){
    int l = lca(u,v) ;
    return (sum[u] + sum[v] - ( sum[l]<<1LL )) ;
  }
  void dfs(int u, int p , int curSum){
    st[u] = ++Time ; par[u] = p ; sum[u] = curSum ;
    for(int i=0 ; i<g[u].size() ; i++){
      if( g[u][i]==p ) continue ;
      dfs( g[u][i] ,u,curSum+weight[u][i]) ;
    }
    en[u] = ++Time ; a[++cur] = u ; id[u] = cur ;
  }
  void build(){
    cur = Time = 0 ; dfs( r , r , 0 );
    for(int i=1 ; i<=n ; i++) dp[0][i] = a[i] ;
    for(int l=0 ; l<LOG-1 ; l++) {
      for(int i=1 ; i<=n ; i++) {
        dp[l+1][i] = dp[l][i] ;
        if( (1<<l)+i <= n && sum[dp[l][i+(1<<l)]] <
           sum[dp[l][i]]) dp[l+1][i] = dp[l][ i+(1<<l)] ;
      }
    }
  }
}


// 1-based

class CentroidDecomposition {

    vector<vector<int>> g;
    vector<int> done, ch, par;
    vector<vector<int>> tr, csub;
    int n;

public:


    CentroidDecomposition(int n_) {
        n = n_;
        g.assign(n+1,{});
        csub.assign(n+1,{});
        tr.assign(n+1,{});
        done.assign(n+1,0);
        ch.assign(n+1,0);
        par.assign(n+1,0);
    }

    void addEdge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }
    void dfsSz(int u, int p) {
        ch[u] = 1;
        for (int v : g[u]) {
            if (done[v] or v == p) continue;
            dfsSz(v,u);
            ch[u] += ch[v];
        }
    }
    int dfsFc(int u, int p, int sz) {
        for (int v : g[u]) {
            if (!done[v] and v != p and ch[v] > sz) {
                return dfsFc(v, u, sz) ;
            }
        }
        return u;
    }
    void dfsCsub(int c, int u, vector<int> &vals, int p = 0, int d = 0) {

        if(csub[c].size() == d) csub[c].push_back(vals[u]);
        else csub[c][d] = max(csub[c][d], vals[u]);

        for(int v: g[u]) {
            if (!done[v] and v != p) {
                dfsCsub(c, v, vals, u, d+1);
            }
        }
    }

    void dfsCd(int u, int p, vector<int> &vals) {
        dfsSz(u, 0);
        int c = dfsFc(u, 0, ch[u]/2);
        par[c] = p;
        dfsCsub(c, c, vals);
        for(int i = 1; i < csub[c].size(); i++) {
            csub[c][i] = max(csub[c][i], csub[c][i-1]);
        }
        done[c] = 1;
        for(int v : g[c]) {
            if(!done[v]) {
                dfsCd(v, c, vals);
            }
        }
    }
    bool query(int u, int X) {
        int cur = u;
        while(cur) {
            int more = X - LCA::dis(u, cur);
            if(more < 0) {
                cur = par[cur];
                continue;
            }
            more = min(more, (int)csub[cur].size()-1);
            if(csub[cur][more] > X) return true;
            cur = par[cur];
        }
        return false;
    }
    void go(vector<int> &vals) {
        dfsCd(1, 0, vals);
    }
};

int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    LCA::init(n, 1);
    CentroidDecomposition G(n);
    vector<vector<int>> Graph(n+1);
    for(int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        G.addEdge(u, v);
        Graph[u].push_back(v);
        Graph[v].push_back(u);
        LCA::addEdge(u, v, 1);
    }
    int K;
    cin >> K;
    vector<int> src(n+1);
    queue<int> que;
    vector<int> dis(n+1, 1e9);
    for(int i = 0; i < K; i++) {
        int x;
        cin >> x;
        src[x] = 1;
        dis[x] = 0;
        que.push(x);
    }
    while(!que.empty()) {
        int u = que.front();
        que.pop();
        for(int v : Graph[u]) {
            if(dis[v] > dis[u]+1) {
                dis[v] = dis[u]+1;
                que.push(v);
            }
        }
    }
    G.go(dis);
    vector<int> lo(n+1, 0), hi(n+1, n);
    LCA::build();
    for(int itr = 1; itr <= 20; itr++) {
        vector<int> mid(n+1);
        for(int i = 1; i <= n; i++) mid[i] = (lo[i]+hi[i]+1)/2;
        for(int i = 1; i <= n; i++) {
            if(G.query(i, mid[i])) lo[i] = mid[i];
            else hi[i] = mid[i]-1;
        }
    }
    for(int i = 1; i <= n; i++) {
        if(dis[i] == 0) cout << "0 ";
        else cout << lo[i]+1 << " ";
    }
}