import java.util.*;
public class Solution
{
    static boolean flag;
    static int[] aa,ss;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n=0;
        ArrayList<ArrayList<Integer>> list=new ArrayList<>();
        if(scan.hasNext())
            n = scan.nextInt();
        for(int i=0;i<n;i++){
            list.add(new ArrayList<>());
        }
        HashSet<Integer> set1=new HashSet<>(),set2=new HashSet<>();
        HashMap<Integer,Integer> map=new HashMap<>();
        int[][] arr=new int[n-1][2];
        for(int i=0;i<n-1;i++){
            if(scan.hasNext())
                arr[i][0]=scan.nextInt()-1;
            if(scan.hasNext())
                arr[i][1]=scan.nextInt()-1;
            map.put(arr[i][1],arr[i][0]);
            set1.add(arr[i][0]);
            set2.add(arr[i][1]);
        }
        Iterator<Integer> it=set2.iterator();
        Queue<Integer> q=new ArrayDeque<>();
        while(it.hasNext()){
            int a=it.next();
            if(!set1.contains(a)){
                q.add(a);
            }
        }
        int j=0;
        HashMap<Integer,pair> mm=new HashMap<>();
        while(q.size()>0){
            int u=q.poll();
            if(map.containsKey(u)){
                int p=map.get(u);
                mm.put(u,new pair(p,j++));
                q.add(p);
            }

        }
        for(int i=0;i<n-1;i++){
            pair w=mm.get(arr[i][1]);
            System.out.println(w.b);
        }



    }
    static class pair{
        int a,b;
        public pair(int a,int b){
            this.a=a;
            this.b=b;
        }
    }


}



