You are given a rooted undirected tree consisting of $n$ vertices. Vertex $1$ is the root.

Let's denote a depth array of vertex $x$ as an infinite sequence $[d_{x, 0}, d_{x, 1}, d_{x, 2}, \dots]$, where $d_{x, i}$ is the number of vertices $y$ such that both conditions hold:
 -  $x$ is an ancestor of $y$; -  the simple path from $x$ to $y$ traverses exactly $i$ edges. 
The dominant index of a depth array of vertex $x$ (or, shortly, the dominant index of vertex $x$) is an index $j$ such that:
 -  for every $k &lt; j$, $d_{x, k} &lt; d_{x, j}$; -  for every $k &gt; j$, $d_{x, k} \le d_{x, j}$. 
For every vertex in the tree calculate its dominant index.
The first line contains one integer $n$ ($1 \le n \le 10^6$) — the number of vertices in a tree.

Then $n - 1$ lines follow, each containing two integers $x$ and $y$ ($1 \le x, y \le n$, $x \ne y$). This line denotes an edge of the tree.

It is guaranteed that these edges form a tree.
4
1 2
2 3
3 4
0
0
0
0
4
1 2
1 3
1 4
1
0
0
0
4
1 2
2 3
2 4
2
1
0
0
1
0
2
1 2
0
0
import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
from collections import defaultdict
 
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.ar = [[1] for i in range(n)]
        self.max = [1 for i in range(n)]
        self.idx = [0 for i in range(n)]
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if len(self.ar[x]) < len(self.ar[y]):
            x, y = y, x

        m = len(self.ar[y])
        for i in range(m):
            self.ar[x][-1-i] += self.ar[y][-1-i]
            if self.max[x] < self.ar[x][-1-i]:
                self.max[x] = self.ar[x][-1-i]
                self.idx[x] = i
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members
 
    def __str__(self):
        return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items())
n = ni()
g = [[] for i in range(n)]

for _ in range(n-1):
    u, v = na()
    u-=1
    v-=1
    g[u].append(v)
    g[v].append(u)

et = []
d = [0]
seen = [0] * n
chi = [[] for i in range(n)]

while d:
    x = d.pop()
    et.append(x)
    seen[x] = 1
    for y in g[x]:
        if seen[y]:continue
        chi[x].append(y)
        d.append(y)
uf = UnionFind(n)
ans = [-1] * n
for i in et[::-1]:
    for j in chi[i]:
        uf.ar[uf.find(j)].append(0)
        uf.idx[uf.find(j)] += 1
        uf.union(i, j)
        #print(i+1, j+1, uf.ar[uf.find(i)][::-1])
    ans[i] = uf.idx[uf.find(i)]

for i in ans:
    print(i)
