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

public class Main {

    static ArrayList<Integer>[] a;
    static int[] ans;
    static boolean govna = false;
    static boolean[] used;
    static int cnt = 1;
    static TreeMap<point, Integer> tm = new TreeMap<>((o1, o2) -> Integer.compare(o1.a, o2.a) * 2 + Integer.compare(o1.b, o2.b));
    static int ind2 = 0;

    static boolean dfs(int v, int p) {
        used[v] = true;
        boolean j = true;
        if (v == ind2) j = false;
        for (int to : a[v]) {
            if (!used[to]) {
                if (!dfs(to, v)) j = false;
            }
        }
        if (!j && !govna) {
            ans[tm.get(new point(Math.min(p, v), Math.max(p, v)))] = 3;
            govna = true;
            return false;
        }
        if (p != -1 && v != ind2 && ans[tm.get(new point(Math.min(v, p), Math.max(v, p)))] != 1)
            ans[tm.get(new point(Math.min(v, p), Math.max(v, p)))] = cnt++;
        return j;
    }

    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int n = in.nextInt();
        used = new boolean[n];
        ans = new int[n];
        a = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            a[i] = new ArrayList<>();
        }
        for (int i = 0; i < n - 1; i++) {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            a[from].add(to);
            a[to].add(from);
            tm.put(new point(Math.min(from, to), Math.max(from, to)), i);
        }
        int one = 0;
        int two = 0;
        for (int i = 0; i < n; i++) {
            if (a[i].size() == 1) one++;
            if (a[i].size() == 2) two++;
        }
        if (one == 2 && two == n - 2) {
            for (int i = 0; i < n - 1; i++) {
                in.out.println(i);
            }
        } else {
            int cnt = 1;
            for (int i = 0; i < n; i++) {
                if (a[i].size() == 1) {
                    ans[tm.get(new point(Math.min(i, a[i].get(0)), Math.max(i, a[i].get(0))))] = cnt++;
                }
            }
            for (int i = 0; i < n - 1; i++) {
                if (ans[i] == 0) {
                    in.out.println(cnt++ -1 );
                } else in.out.println(--ans[i]);
            }
        }
        in.out.close();
    }
}

class point {
    int a, b;

    public point(int a, int b) {
        this.a = a;
        this.b = b;
    }
}


class FastScanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    PrintWriter out;

    FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    FastScanner(String in, String out_) throws FileNotFoundException {
        br = new BufferedReader(new FileReader(in));
        out = new PrintWriter(out_);
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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