You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:

  * Every label is an integer between 0 and n-2 inclusive. 
  * All the written labels are distinct. 
  * The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as possible. 



Here, MEX(u,v) denotes the smallest non-negative integer that isn't written on any edge on the unique simple path from node u to node v.

Input

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

Each of the next n-1 lines contains two space-separated integers u and v (1 ≤ u,v ≤ n) that mean there's an edge between nodes u and v. It's guaranteed that the given graph is a tree.

Output

Output n-1 integers. The i^{th} of them will be the number written on the i^{th} edge (in the input order).

Examples

Input


3
1 2
1 3


Output


0
1


Input


6
1 2
1 3
2 4
2 5
5 6


Output


0
3
2
4
1

Note

The tree from the second sample:

<image>
import java.io.*;
import java.util.*;

/**
 * Created by Katushka on 11.03.2020.
 */
public class EhabAndPatheticMEX {
    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static class Vertex {
        int num;

        List<Vertex> children = new ArrayList<>();

        public Vertex(int num) {
            this.num = num;
        }
    }

    static class Edge {
        int v1;
        int v2;

        public Edge(int v1, int v2) {
            this.v1 = Math.min(v1, v2);
            this.v2 = Math.max(v1, v2);
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Edge edge = (Edge) o;

            if (v1 != edge.v1) return false;
            return v2 == edge.v2;
        }

        @Override
        public int hashCode() {
            int result = v1;
            result = 31 * result + v2;
            return result;
        }
    }

    public static void main(String[] args) throws FileNotFoundException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = in.nextInt();
        Vertex[] vertices = new Vertex[n];
        for (int i = 0; i < n; i++) {
            vertices[i] = new Vertex(i);
        }
        Edge[] allEdges = new Edge[n - 1];
        Map<Edge, Integer> edges = new HashMap<>();
        for (int i = 0; i < n - 1; i++) {
            int v1 = in.nextInt();
            int v2 = in.nextInt();

            Edge edge = new Edge(v1 - 1, v2 - 1);
            allEdges[i] = edge;
            edges.put(edge, i);
            vertices[v1-1].children.add(vertices[v2 - 1]);
            vertices[v2 - 1].children.add(vertices[v1 - 1]);
        }
        if (n == 2) {
            out.println(0);
        } else {
            Set<Integer> visited = new HashSet<>();
            int v = 0;
            for (Vertex vertex : vertices) {
                if (vertex.children.size() == 1) {
                    v = vertex.num;
                    break;
                }
            }
            ArrayList<Integer> path = new ArrayList<>();
            int len = findPath(v, vertices, visited, path);
            if (len == n) {
                for (int i = 0; i < n - 1; i++) {
                    out.println(i);
                }
            } else {
                int[] edgeNums = new int[n - 1];
                for (int i = 0; i < edgeNums.length; i++) {
                    edgeNums[i] = -1;
                }

                edgeNums[edges.get(new Edge(path.get(0), path.get(1)))] = 0;
                edgeNums[edges.get(new Edge(path.get(path.size() - 2), path.get(path.size() - 1)))] = 1;
                for (int i = 1; i < path.size() - 2; i++) {
                    edgeNums[edges.get(new Edge(path.get(i), path.get(i + 1)))] = 2 + i;
                }
                boolean twoPut = false;
                int k = path.size();
                for (int i = 0; i < edgeNums.length; i++) {
                    if (edgeNums[i] == -1) {
                        if (!twoPut) {
                            edgeNums[i] = 2;
                            twoPut = true;
                        } else {
                            edgeNums[i] = k;
                            k++;
                        }
                    }

                }
                for (int edgeNum : edgeNums) {
                    out.println(edgeNum);
                }
            }
        }

        out.close();
    }

    private static int findPath(int v, Vertex[] vertices, Set<Integer> visited, List<Integer> path) {
        visited.add(v);
        path.add(v);
        int pathLen = 1;
        for (int i = 0; i < vertices[v].children.size(); i++) {
            Vertex vertex = vertices[v].children.get(i);
            if (!visited.contains(vertex.num)) {
                pathLen += findPath(vertex.num, vertices, visited, path);
                break;
            }
        }
        return pathLen;
    }


    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}
