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}, ...], 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 < j, d_{x, k} < d_{x, j}; 
  * for every k > j, d_{x, k} ≤ d_{x, j}. 



For every vertex in the tree calculate its dominant index.

Input

The first line contains one integer n (1 ≤ n ≤ 10^6) — the number of vertices in a tree.

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

It is guaranteed that these edges form a tree.

Output

Output n numbers. i-th number should be equal to the dominant index of vertex i.

Examples

Input

4
1 2
2 3
3 4


Output

0
0
0
0


Input

4
1 2
1 3
1 4


Output

1
0
0
0


Input

4
1 2
2 3
2 4


Output

2
1
0
0
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.Reader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyInput in = new MyInput(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, MyInput in, PrintWriter out) {
            int n = in.nextInt();
            Graph g = new Graph(n);
            for (int i = 0; i < n - 1; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                g.addEdge(a, b, 1, i);
                g.addEdge(b, a, 1, i);
            }
            Tree t = g.dfsTree(0);
//        t.hld();
            C[] c = new C[n];
            int[] ans = new int[n];
            for (int v : t.inversedDfsOrder()) {
                for (Edge e : t.edges(v)) {
                    if (c[v] == null) c[v] = c[e.to];
                    else c[v].merge(c[e.to]);
                }
                if (c[v] == null) c[v] = new C();
                c[v].inc();
                ans[v] = c[v].idx;
            }
            for (int a : ans) out.println(a);
        }

        class ArrayInt {
            int len;
            int[] ary;

            ArrayInt(int capacity) {
                ary = new int[capacity];
            }

            void add(int x) {
                if (ary.length == len) {
                    int[] tmp = new int[ary.length * 2];
                    System.arraycopy(ary, 0, tmp, 0, len);
                    ary = tmp;
                }
                ary[len++] = x;
            }

            int size() {
                return len;
            }

            int get(int idx) {
                return ary[idx];
            }

            void swap(ArrayInt a) {
                int[] ta = ary;
                ary = a.ary;
                a.ary = ta;

                int tl = len;
                len = a.len;
                a.len = tl;
            }

        }

        class C {
            int idx;
            ArrayInt cnt = new ArrayInt(1);

            void inc() {
                cnt.add(1);
                if (cnt.size() != 1 && cnt.get(cnt.size() - 1 - idx - 1) != 1) {
                    idx++;
                }
            }

            void merge(C c) {
                if (cnt.size() < c.cnt.size()) {
                    c.cnt.swap(cnt);

                    int ti = idx;
                    idx = c.idx;
                    c.idx = ti;
                }

                for (int i = 0; i < c.cnt.size(); i++) {
                    cnt.ary[cnt.size() - 1 - i] += c.cnt.get(c.cnt.size() - 1 - i);
                    int cidx = cnt.get(cnt.size() - 1 - idx);
                    int ci = cnt.get(cnt.size() - 1 - i);
                    if (cidx < ci || cidx == ci && idx > i) {
                        idx = i;
                    }
                }
            }

        }

        class Edge {
            public final int edgeId;
            public final int to;
            public long cost;

            public Edge(int to, long cost, int edgeId) {
                this.to = to;
                this.cost = cost;
                this.edgeId = edgeId;
            }


            public String toString() {
                return String.format("[Edge id=%d, to=%d, cost=%d]", edgeId, to, cost);
            }

        }

        class Vertex {
            public final int id;
            public final List<Edge> edges = new ArrayList<>();

            public Vertex(final int id) {
                this.id = id;
            }

            public void addEdge(Edge e) {
                edges.add(e);
            }

        }

        class Tree {
            private int V;
            private int root;
            private Vertex[] vertex;
            private int[] dfsOrder;
            private int[] invDfsOrder;

            public Tree(int V, int root) {
                this.V = V;
                this.root = root;
                vertex = new Vertex[V];
                for (int i = 0; i < V; i++) vertex[i] = new Vertex(i);
            }

            public void addEdge(int s, Edge e) {
                vertex[s].addEdge(e);
            }

            public List<Edge> edges(int v) {
                return vertex[v].edges;
            }

            public int[] dfsOrder() {
                if (dfsOrder == null) {
                    dfsOrder = new int[V];
                    int[] st = new int[V];
                    int sp = 0, len = 0;
                    boolean[] vis = new boolean[V];

                    vis[root] = true;
                    st[sp++] = root;
                    while (sp > 0) {
                        int v = st[--sp];
                        dfsOrder[len++] = v;
                        for (Edge e : vertex[v].edges)
                            if (!vis[e.to]) {
                                vis[e.to] = true;
                                st[sp++] = e.to;
                            }
                    }
                }
                return dfsOrder;
            }

            public int[] inversedDfsOrder() {
                if (invDfsOrder == null) {
                    invDfsOrder = TaskF.ArrayAlgorithms.reverse(dfsOrder());
                }
                return invDfsOrder;
            }

        }

        class Graph {
            int V;
            int E;
            Vertex[] vertex;

            public Graph(int V) {
                this.V = V;
                this.E = 0;
                vertex = new Vertex[V];
                for (int i = 0; i < V; i++) vertex[i] = new Vertex(i);
            }

            public void addEdge(int s, int t, long c, int edgeId) {
                vertex[s].addEdge(new Edge(t, c, edgeId));
            }

            public Tree dfsTree(int r) {
                Tree tree = new Tree(V, r);
                int[] st = new int[V];
                int sp = 0;
                boolean[] vis = new boolean[V];

                vis[r] = true;
                st[sp++] = r;
                while (sp > 0) {
                    int v = st[--sp];
                    for (Edge e : vertex[v].edges)
                        if (!vis[e.to]) {
                            vis[e.to] = true;
                            st[sp++] = e.to;
                            tree.addEdge(v, e);
                        }
                }
                return tree;
            }

        }

        static class ArrayAlgorithms {
            public static int[] reverse(int[] ary) {
                int V = ary.length;
                int[] res = new int[ary.length];
                for (int i = 0; i < V; i++) {
                    res[i] = ary[V - 1 - i];
                }
                return res;
            }

        }

    }

    static class MyInput {
        private final BufferedReader in;
        private static int pos;
        private static int readLen;
        private static final char[] buffer = new char[1024 * 8];
        private static char[] str = new char[500 * 8 * 2];
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];
        private static boolean[] isLineSep = new boolean[256];

        static {
            for (int i = 0; i < 10; i++) {
                isDigit['0' + i] = true;
            }
            isDigit['-'] = true;
            isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
            isLineSep['\r'] = isLineSep['\n'] = true;
        }

        public MyInput(InputStream is) {
            in = new BufferedReader(new InputStreamReader(is));
        }

        public int read() {
            if (pos >= readLen) {
                pos = 0;
                try {
                    readLen = in.read(buffer);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (readLen <= 0) {
                    throw new MyInput.EndOfFileRuntimeException();
                }
            }
            return buffer[pos++];
        }

        public int nextInt() {
            int len = 0;
            str[len++] = nextChar();
            len = reads(len, isSpace);
            int i = 0;
            int ret = 0;
            if (str[0] == '-') {
                i = 1;
            }
            for (; i < len; i++) ret = ret * 10 + str[i] - '0';
            if (str[0] == '-') {
                ret = -ret;
            }
            return ret;
        }

        public char nextChar() {
            while (true) {
                final int c = read();
                if (!isSpace[c]) {
                    return (char) c;
                }
            }
        }

        int reads(int len, boolean[] accept) {
            try {
                while (true) {
                    final int c = read();
                    if (accept[c]) {
                        break;
                    }
                    if (str.length == len) {
                        char[] rep = new char[str.length * 3 / 2];
                        System.arraycopy(str, 0, rep, 0, str.length);
                        str = rep;
                    }
                    str[len++] = (char) c;
                }
            } catch (MyInput.EndOfFileRuntimeException e) {
            }
            return len;
        }

        static class EndOfFileRuntimeException extends RuntimeException {
        }

    }
}

