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<Integer>[] adj = new ArrayList[n];
        for(int i = 0; i<n; i++) adj[i] = new ArrayList<>();
        for(int i = 0; i<n-1; i++){
            String[] str = br.readLine().split(" ");
            int u = Integer.parseInt(str[0])-1, v = Integer.parseInt(str[1])-1;
            adj[u].add(i);
            adj[v].add(i);
        }
        int[] ans = new int[n-1];
        Arrays.fill(ans, -1);
        int num = 0;
        for(int i = 0; i<n; i++){
            if(adj[i].size()>=3){
                for(int j = 0; j<3; j++){
                    ans[adj[i].get(j)] = num++;
                }
                break;
            }
        }
        for(int i = 0; i<n-1; i++){
            if(ans[i] == -1) ans[i] = num++;
        }
        for(int i = 0; i<n-1; i++){
            sb.append(ans[i]).append('\n');
        }
        System.out.println(sb);
    }
}