import java.io.*;
import java.math.BigDecimal;
import java.util.*;

public class Day9 {
    public static class Edge{
        int to;
        int ind;
        public Edge(int t, int i){
            this.to = t;
            this.ind = i;
        }
    }
    public static boolean[] used;
    public static int[] color;
    public static ArrayList<Edge>[] graph;
    public static ArrayList<Integer> lists;
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(System.out);
        int n = Integer.parseInt(reader.readLine());
        graph = new ArrayList[n];
        for(int i = 0; i < n; ++i){
            graph[i] = new ArrayList<>();
        }
        used = new boolean[n];
        color = new int[n];
        for(int i = 0; i < n; ++i){
            color[i] = -1;
        }
        for(int i = 0; i < n - 1; ++i){
            StringTokenizer st = new StringTokenizer(reader.readLine());
            int f = Integer.parseInt(st.nextToken()) - 1;
            int s = Integer.parseInt(st.nextToken()) - 1;
            graph[f].add(new Edge(s, i));
            graph[s].add(new Edge(f,i));
        }
        lists = new ArrayList<>();
        int c = 0;
        for(int i = 0; i < n; ++i){
            if(graph[i].size() == 1){
                int ind = graph[i].get(0).ind;
                if(color[ind] == -1){
                    color[ind] = c++;
                }
            }
        }
        for(int i = 0; i < n - 1; ++i){
            if(color[i] == -1){
                color[i] = c++;
            }
        }
        for(int i = 0; i < n - 1; ++i){
            writer.println(color[i]);
        }
        writer.close();
    }
}