import java.util.*;
public class Solution
{
    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<>();
        int[][] arr=new int[n][2];
        for(int i=0;i<n-1;i++){
            if(scan.hasNext())
                arr[i][0]=scan.nextInt();
            if(scan.hasNext())
                arr[i][1]=scan.nextInt();
            list.get(arr[i][0]).add(arr[i][1]);
            set1.add(arr[i][0]);
            set2.add(arr[i][1]);
        }
        Iterator<Integer> it=set2.iterator();
        int j=0;
        while(it.hasNext()){
            j=it.next();
            if(!set1.contains(j)){
                break;
            }
        }
        int k=1;
        for(int i=0;i<n-1;i++){
            if(arr[i][1]==j){
                System.out.println(0);
            }else{
                System.out.println(k++);
            }
        }




    }

}



