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

public class Main {
    private FastScanner in;
    private PrintWriter out;

    public static void main(String[] args) {
        (new Main()).run();
    }

    private void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
            solution();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (out != null) out.close();
        }
    }

    private void solution() throws IOException {
        int n = in.nextInt();
        List<List<Edge>> ways = new ArrayList<>(n);
        for(int i=0;i<n;i++){
            ways.add(new LinkedList<>());
        }
        List<Edge> edges = new ArrayList<>();
        List<Integer> weights = new ArrayList<>(n - 1);
        for(int i=0;i<n-1;i++){
            int u = in.nextInt() - 1;
            int v = in.nextInt() - 1;
            Edge edge = new Edge(u, v);
            edges.add(edge);
            ways.get(u).add(edge);
            ways.get(v).add(edge);
        }
        Queue<Integer> queue = new ArrayDeque<>();
        for(int i=0;i<n;i++){
            if(ways.get(i).size() == 1){
                queue.add(i);
            }
        }
        int count = 0;
        while (!queue.isEmpty()){
            int vertex = queue.poll();
            if(ways.get(vertex).isEmpty()){
                break;
            }
            Edge edge = ways.get(vertex).iterator().next();
            edge.setWeight(count++);
            int parent = edge.getU() + edge.getV() - vertex;
            ways.get(parent).remove(edge);
            queue.add(parent);
        }
        edges.stream().map(Edge::getWeight).forEach(out::println);
    }

    private class Edge{
        int u;
        int v;
        int weight;

        public Edge(int u, int v) {
            this.u = u;
            this.v = v;
        }

        public int getU() {
            return u;
        }

        public int getV() {
            return v;
        }

        public int getWeight() {
            return weight;
        }

        public void setWeight(int weight) {
            this.weight = weight;
        }
    }


    private class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        String next() throws IOException {
            while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                String temp = bufferedReader.readLine();
                if (temp == null) {
                    return null;
                }
                stringTokenizer = new StringTokenizer(temp);
            }
            return stringTokenizer.nextToken();
        }

        String nextLine() throws IOException {
            return bufferedReader.readLine();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        void close() throws IOException {
            bufferedReader.close();
        }
    }
}