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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int n = sc.nextInt();
        Map<Integer, List<Integer>> tree = new HashMap<>();
        boolean[] isRoot = new boolean[n];
        for (int i = 0; i < n; i++) {
            isRoot[i] = true;
        }
        List<List<Integer>> order = new ArrayList<>();
        for (int i = 0; i < n-1; i++) {
            int u = sc.nextInt();
            int v = sc.nextInt();
            List<Integer> pair = Arrays.asList(u,v);
            order.add(pair);
            isRoot[v-1] = false;
            tree.computeIfAbsent(u, integer -> new ArrayList()).add(v);
        }
        int root = 0;
        for (int i = 0; i < n; i++) {
            if(isRoot[i]) {
                root = i+1;
                break;
            }
        }

        Map<List<Integer>, Integer> output = bfs(root, tree, n);
        for(List<Integer> in : order) {
            System.out.println(output.get(in));
        }
    }

    private static Map<List<Integer>, Integer> bfs(int root, Map<Integer, List<Integer>> tree, int n) {
        Queue<Integer> queue = new ArrayDeque<>();
        queue.add(root);
        int counter = n-2;
        Map<List<Integer>, Integer> output = new HashMap<>();
        boolean isFirst = true;
        while (!queue.isEmpty()) {
            int current = queue.poll();
            for (int adj : tree.getOrDefault(current, Collections.emptyList())) {
                queue.add(adj);
                if(isFirst) {
                    output.put(Arrays.asList(current,adj), 0);
                    isFirst = false;
                }
                else {
                    output.put(Arrays.asList(current, adj), counter--);
                }
            }
        }
        return output;
    }
}