import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class CEhabAndPathEticMEXs {
        static CEhabAndPathEticMEXs.Node[] graph;
        static boolean[] visited;
        static CEhabAndPathEticMEXs.Edge[] edges;
        static int n;
        static int act;

        static void dfs(int a) {
            visited[a] = true;
            for (CEhabAndPathEticMEXs.Pair p : graph[a].edges) {
                if (edges[p.y].value == -1) {
                    edges[p.y].value = act;
                    act--;
                }
                if (!visited[p.x]) {
                    dfs(p.x);
                }
            }
        }

        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            n = sc.nextInt();
            graph = new CEhabAndPathEticMEXs.Node[n];
            visited = new boolean[n];
            for (int i = 0; i < n; i++) {
                graph[i] = new CEhabAndPathEticMEXs.Node();
                graph[i].edges = new ArrayList<>();
            }
            edges = new CEhabAndPathEticMEXs.Edge[n - 1];
            for (int i = 0; i < n - 1; i++) {
                int u = sc.nextInt() - 1;
                int v = sc.nextInt() - 1;
                graph[v].edges.add(new CEhabAndPathEticMEXs.Pair(u, i));
                graph[u].edges.add(new CEhabAndPathEticMEXs.Pair(v, i));
                edges[i] = new CEhabAndPathEticMEXs.Edge(u, v, i);
            }
            edges[0].value = 0;
            act = n - 2;
            for (CEhabAndPathEticMEXs.Pair p : graph[edges[0].u].edges) {
                if (p.x != edges[0].v) {
                    edges[p.y].value = act;
                    act--;
                }
            }
            for (CEhabAndPathEticMEXs.Pair p : graph[edges[0].v].edges) {
                if (p.x != edges[0].u) {
                    edges[p.y].value = act;
                    act--;
                }
            }
            dfs(0);
            for (int i = 0; i < n - 1; i++) {
                out.println(edges[i].value);
            }

        }

        static class Node {
            ArrayList<CEhabAndPathEticMEXs.Pair> edges;

        }

        static class Edge {
            int u;
            int v;
            int idx;
            int value;

            public Edge(int u, int v, int idx) {
                this.u = u;
                this.v = v;
                this.idx = idx;
                this.value = -1;
            }

        }

        static class Pair {
            int x;
            int y;

            public Pair(int x, int y) {
                this.x = x;
                this.y = y;
            }

        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}

