import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Queue;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author bhavy seth
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            int n = sc.nextInt();
            ArrayList<Pair> list = new ArrayList<>();
            ArrayList<Integer> a[] = new ArrayList[n + 1];
            for (int i = 0; i <= n; i++) {
                a[i] = new ArrayList<>();
            }
            for (int i = 0; i < n - 1; i++) {
                int u = sc.nextInt();
                int v = sc.nextInt();
                a[u].add(v);
                list.add(new Pair(u, v));
            }
            HashMap<Pair, Integer> map = new HashMap();
            boolean vis[] = new boolean[n + 1];
            Queue<Integer> q = new LinkedList<>();
            q.add(1);
            vis[1] = true;
            int count = n - 2;
            while (!q.isEmpty()) {
                int uv = q.poll();
                // out.println(uv);
                for (int i = 0; i < a[uv].size(); i++) {
                    int ver = a[uv].get(i);
                    if (true) {

                        map.put(new Pair(uv, ver), count);
                        count--;
                        q.add(ver);
                        vis[ver] = true;
                    }
                }
            }
            for (int i = 0; i < list.size(); i++) {
                out.println(map.get(list.get(i)));
            }

        }

    }

    static class Pair {
        public final int x;
        public final int y;

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

        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Pair)) return false;
            Pair key = (Pair) o;
            return x == key.x && y == key.y;
        }

        public int hashCode() {
            int result = x;
            result = 31 * result + y;
            return result;
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}

