import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Solution {
    static class Pair {
        int v;
        int pos;

        public Pair(int v, int pos) {
            this.v = v;
            this.pos = pos;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(bf.readLine());
        if (n == 2) {
            System.out.println("0");
            System.out.println("1");
            return;
        }

        List<List<Pair>> tree = Stream.generate((Supplier<ArrayList<Pair>>) ArrayList::new)
                .limit(n).collect(Collectors.toList());
        for (int i = 0; i < n - 1; i++) {
            String[] line = bf.readLine().split("\\s");
            int u = Integer.parseInt(line[0])-1;
            int v = Integer.parseInt(line[1])-1;
            tree.get(u).add(new Pair(v,i));
            tree.get(v).add(new Pair(u,i));
        }
        List<Integer> leafs = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (tree.get(i).size() == 1){
                leafs.add(i);
            }
        }
        if (leafs.size() <= 2){
            for (int i = 1; i < n; i++) {
                System.out.println(i);
            }
            return;
        }
        int[] ans = new int[n-1];
        for (int i = 0; i < leafs.size(); i++) {
            ans[tree.get(leafs.get(i)).get(0).pos] = i+1;
        }
        int c = leafs.size()+1;
        for (int i = 0; i < ans.length; i++) {
            if (ans[i] == 0){
                ans[i] = c++;
            }
        }
        for (int an : ans) {
            System.out.println(an);
        }
    }
}
