
import java.io.*;
import java.util.*;

public class Test {
//

//    private static int c = 1000010;
    private static int r = 1000_000_007;

    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();

        List<Node> nodes = new ArrayList<>();
        List<Edge> edges = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            nodes.add(new Node(i));
        }
        int u, v;
        for (int i = 0; i < n - 1; i++) {
            u = in.nextInt() - 1;
            v = in.nextInt() - 1;
            Edge e = new Edge(u, v, i);
            nodes.get(u).edgs.add(e);
            nodes.get(v).edgs.add(e);
            edges.add(e);
        }
        
        if (n <= 4) {
            for (int i = 0; i < n - 1; i++) {
                System.out.println(i);
            }
        } else {
            List<Node> l = new ArrayList<>();
            for (Node node : nodes) {
                if (node.edgs.size()==1) {
                    l.add(node);
                }
            }
            
            boolean[] b1 = new boolean[n - 1];

            boolean dfs = dfs(nodes, l.get(0), l.get(1), b1);
            
            
            int y = -1;
            for (int i = 0; i < n - 1; i++) {
                if (!b1[i]) {
                    y = i;
                    break;
                }
            }
            StringBuffer sb = new StringBuffer();
            if (y == -1) {
                for (int i = 0; i < n - 1; i++) {
                    sb.append(i + "\n");
                }
            } else {
                edges.get(y).x = 0;
                l.get(0).edgs.get(0).x = 1;
                l.get(1).edgs.get(0).x = 2;
                int i = 3;
                for (Edge e : edges) {
                    if (e.x == -1) {
                        e.x = i++;
                    }
                }

                Collections.sort(edges, (e1, e2) -> {
                    return e1.i - e2.i;
                });

                for (i = 0; i < edges.size(); i++) {
                    sb.append(edges.get(i).x + "\n");
                }
            }
            
            System.out.print(sb);
        }
    }

    private static boolean dfs(List<Node> nodes, Node n1, Node n2, boolean[] b1) {
        if (n1.number == n2.number) {
            return true;
        }
        for (Edge e : n1.edgs) {
            if (!b1[e.i]) {
                b1[e.i] = true;
                
                if (e.u == n1.number) {
                    boolean b = dfs(nodes, nodes.get(e.v), n2, b1);
                    if (b) {
                        return true;
                    }
                } else {
                    if (dfs(nodes, nodes.get(e.u), n2, b1)) {
                        return true;
                    }
                }
                b1[e.i] = false;
            }
        }
        return false;
    }

}

class Edge {

    int u, v, i, x;

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

}

class Node {

    int number;
    List<Edge> edgs;

    public Node(int number) {
        this.number = number;
        edgs = new ArrayList<>();
    }

}

class FastScanner {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");

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

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

    int[] readArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

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