import javafx.util.Pair;
import java.util.*;

public class CF1325C {

    public static void main(String ...args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        ArrayList<Pair<Integer, Integer>> edges = new ArrayList<>();
        int[] degree = new int[n+1];
        for(int i = 1;i<n;i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            edges.add(new Pair<>(u,v));
            degree[u]++;
            degree[v]++;
        }

        int small = 0;
        int large = n-1;
        int[] ans = new int[n-1];

        for(int i = 0;i<n-1;i++) {
            Pair<Integer, Integer> edge = edges.get(i);
            if (degree[edge.getKey()] == 1 || degree[edge.getValue()] == 1) {
                ans[i] = small++;
            } else {
                ans[i] = large--;
            }
        }

        for(int i: ans) {
            System.out.println(i);
        }
    }

}
