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

public class Main {
    public static void solve() {
        int n = in.nextInt();
        int[] ans = new int[n];
        Arrays.fill(ans, -1);
        List<Integer>[] graph = new List[n + 1];
        for (int i = 1; i <= n; i++) {
            graph[i] = new ArrayList<>();
        }

        for (int i = 1; i < n; i += 1) {
            int from = in.nextInt();
            int to = in.nextInt();

            graph[from].add(i);
            graph[to].add(i);
        }

        int at = 0;
        for (int i = 1; i <= n; i += 1) {
            if (graph[i].size() > 2) {
                ans[graph[i].get(0)] = 0;
                ans[graph[i].get(1)] = 1;
                ans[graph[i].get(2)] = 2;
                at = 3;
                break;
            }
        }

        for (int i = 1; i < n; i += 1) {
            if (ans[i] == -1) {
                ans[i] = at;
                at += 1;
            }

        }

        for (int i = 1; i < n; i += 1)
            out.println(ans[i]);

    }

    public static InputReader in = new InputReader();
    public static PrintWriter out;

    public static void main(String[] args) {
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    private static final long mod = (long) (1e9 + 7);

    private static long pow(long a, long b) {
        if (b == 0)
            return 1L;

        long val = pow(a, b / 2);

        if (b % 2 == 0)
            return val * val % mod;
        else
            return val * val % mod * a % mod;
    }

    private static class Pair<K, V> {
        K first;
        V second;

        public Pair(K first, V second) {
            this.first = first;
            this.second = second;
        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
                tokenizer = null;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }
    }
}