
import java.util.*;

public class Question6283 {
    int start=0;
    public static void main(String[] args) {
        int n;
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();

        ArrayList []t=new ArrayList[n+1];
        boolean flag[]=new boolean[n+1];
        Map<String,Integer> map=new HashMap<String, Integer>();
        for (int i=0;i<n-1;i++){
            int x=sc.nextInt();
            int y=sc.nextInt();
            flag[y]=true;

            map.put(x+","+y,i);
            if(t[x]==null){
                ArrayList<Integer> list=new ArrayList<Integer>();
                list.add(y);
                t[x]=list;
            }else{
                t[x].add(y);
            }
        }
        int i=1;
        for (;i<=n;i++){
            if (flag[i]==false){
                break;
            }
        }
        int root=i;
        int s=0;
        //System.out.println(root);
        int res[]=new int[n-1];
        for(i=0;i<n-1;i++){
            res[i]=-1;
        }
        Question6283 q=new Question6283();
        q.start=0;
        q.traverse(res,root,t,map,-1);
        for(i=0;i<n-1;i++){
            if (res[i]==-1){
                res[i]=q.start++;
            }
            System.out.println(res[i]);
        }
    }

    private  void traverse(int[] res, int root, ArrayList[] t, Map<String, Integer> map, int parent) {
        if (t[root]==null){
            return;
        }


        if (parent!=-1 && t[root].size()>=2){
            int ind=map.get(parent+","+root);
            res[ind]=0;
            ind=map.get(root+","+t[root].get(0));
            res[ind]=1;
            ind=map.get(root+","+t[root].get(1));
            res[ind]=2;
            start=3;
            return;
        }
        for(int i=0;i<t[root].size();i++){
            traverse(res,(Integer) t[root].get(i),t, map, root);
        }
    }
}
