import sun.reflect.generics.tree.Tree;

import java.util.*;

public class Main {


    static class Edge {

        int firstNode;

        int secondNode;

        int num;
        public Edge(int num, int a,  int b){

            this.firstNode = a;

            this.secondNode = b;

            this.num = num;
        }

    }

    static List<Edge>[] nodes;

    static Edge[] edges;

    static int zero; //edge num

    static int one;

    static boolean[] check;

    static int checkCount = 0;
    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        int n = s.nextInt();

        edges = new Edge[n];

        check = new boolean[n];

        nodes = new List[n+1];

        for (int i =0; i < n-1; i++) {

            int first = s.nextInt();

            int second = s.nextInt();

            Edge edge = new Edge(i+1, first, second);

            edges[i+1] = edge;

            if (nodes[first] == null) nodes[first] = new LinkedList<>();

            if (nodes[second] == null) nodes[second] = new LinkedList<>();

            nodes[first].add(edge);

            nodes[second].add(edge);
        }

        Set<Integer> q = new HashSet();

        for (int i = 1; i <= n; i++) {

            List<Edge> edge = nodes[i];

            if (edge.size() == 1) q.add(edge.get(0).num);
        }

        int startNum = 3;

        if (q.size() < 3) startNum = 2;

        int special = 0;

        for (int i = 1 ; i <= n-1; i++) {

            Edge e = edges[i];

            if (q.contains(e.num)) {

                System.out.println(special);

                special++;
            } else {

                System.out.println(startNum);

                startNum++;
            }
        }

    }












}
