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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int n = Integer.parseInt(br.readLine());
        ArrayList<pair> edges = new ArrayList<>();
        int[] deg = new int[n];
        for(int i = 1; i<n; i++){
            String[] str = br.readLine().split(" ");
            int u = Integer.parseInt(str[0])-1, v = Integer.parseInt(str[1])-1;
            edges.add(new pair(u, v));
            deg[u]++;
            deg[v]++;
        }
        if(n == 2){
            System.out.println(0);
            System.exit(0);
        }
        int num = 0, lst = n-2;
        for(int i = 0; i<n-1; i++){
            pair p = edges.get(i);
            if(deg[p.u] >=3 || deg[p.v]>=3){
                System.out.println(num);
                num++;
            }
            else{
                System.out.println(lst);
                lst--;
            }
        }
    }
    static class pair{
        int v, u;
        pair(int a, int b){
            u = a;
            v = b;
        }
    }
}