import java.io.*;
import java.nio.CharBuffer;
import java.util.*;

public class P1325C {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        List<List<Integer>> links = new ArrayList<>();
        for (int i = 0; i < n; ++i)
            links.add(new LinkedList<>());
        HashMap<Tuple, Integer> linkMap = new HashMap<>();
        for (int i = 0; i < n - 1; ++i) {
            int u = scanner.nextInt() - 1;
            int v = scanner.nextInt() - 1;
            links.get(u).add(v);
            links.get(v).add(u);
            linkMap.put(new Tuple(u, v), i);
        }
        LinkedList<Integer> x = search(0, links);
        LinkedList<Integer> y = search(x.peekLast(), links);
        ArrayList<Integer> diameter = new ArrayList<>(y);
        int[] ans = new int[n - 1];
        Arrays.fill(ans, -1);
        int l = diameter.size();
        ans[linkMap.get(new Tuple(diameter.get(0), diameter.get(1)))] = 0;
        if (l > 2)
            ans[linkMap.get(new Tuple(diameter.get(l - 2), diameter.get(l - 1)))] = 1;
        for (int i = 1, cur = n - 2; i < l - 2; ++i) {
            int u = diameter.get(i);
            int v = diameter.get(i + 1);
            ans[linkMap.get(new Tuple(u, v))] = cur--;
        }

        for (int i = 0, cur = 2; i < n - 1; ++i) {
            if (ans[i] < 0)
                ans[i] = cur++;
            writer.println(ans[i]);
        }

        writer.close();
    }


    private static class Tuple {
        public final int x;
        public final int y;

        public Tuple(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Tuple tuple = (Tuple) o;
            return (x == tuple.x && y == tuple.y)
                    ||
                    (x == tuple.y && y == tuple.x);
        }

        @Override
        public int hashCode() {
            return x + y;
        }
    }

    private static LinkedList<Integer> search(int x, List<List<Integer>> links) {
        LinkedList<Integer> queue = new LinkedList<>();
        HashMap<Integer, Integer> fatherMap = new HashMap<>();
        queue.add(x);
        fatherMap.put(x, x);
        int u = x;
        while (!queue.isEmpty()) {
            u = queue.poll();
            for (int v : links.get(u)) {
                if (!fatherMap.containsKey(v)) {
                    queue.offer(v);
                    fatherMap.put(v, u);
                }
            }
        }
        LinkedList<Integer> ans = new LinkedList<>();
        int father = fatherMap.get(u);
        while (u != father) {
            ans.offerFirst(u);
            u = father;
            father = fatherMap.get(u);
        }
        ans.offerFirst(u);
        return ans;
    }


    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        private SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}
