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

public class Main {
    static LinkedList<Edge>[] ll;
    static int g=0;
    static boolean[] vis;
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        StringBuffer sb = new StringBuffer();
        int n=sc.nextInt();
        ll=new LinkedList[n];
        LinkedList<Point> list=new LinkedList<>();
        for(int i=0;i<n;i++)ll[i]=new LinkedList<>();
        for(int i=1;i<n;i++){
            int u=sc.nextInt()-1,v=sc.nextInt()-1;
            ll[u].add(new Edge(v,-1));
            ll[v].add(new Edge(u,-1));
            list.add(new Point(u,v));
        }
        vis=new boolean[n];
        dfs(0,0);
        while(!list.isEmpty()){
            Point p=list.removeFirst();
            for(Edge e:ll[p.x]){
                if(e.v==p.y){
                    sb.append(e.w+"\n");
                }
            }
        }
        System.out.println(sb);
    }
    static void dfs(int i,int parent) {
        vis[i]=true;
        for(Edge node:ll[i]){
            if(!vis[node.v]){
                dfs(node.v,i);
            }
        }
        for(Edge e:ll[parent]){
            if(e.v==i){
                e.w=g++;

            }
        }
    }
    static class Edge{
        int v,w;
        public Edge(int v,int w){
            this.v=v;
            this.w=w;
        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}