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

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        int i,a[]=new int[n];
        ArrayList<Pair> g[]=new ArrayList[n];
        for(i=0;i<n;i++) g[i]=new ArrayList<>();
        for(i=0;i<n-1;i++)
        {
            String s[]=bu.readLine().split(" ");
            int u=Integer.parseInt(s[0])-1,v=Integer.parseInt(s[1])-1;
            g[u].add(new Pair(v,i));
            g[v].add(new Pair(u,i));
        }
        int cur=1; boolean vis[]=new boolean[n];
        Queue<Integer> q=new LinkedList<>();
        q.add(0);
        vis[0]=true;
        while(!q.isEmpty())
        {
            int p=q.poll();
            for(Pair x:g[p])
            if(!vis[x.i])
            {
                vis[x.i]=true;
                a[x.w]=cur++;
                q.add(x.i);
            }
        }
        for(i=0;i<n-1;i++)
        {
            if(a[i]==n-1) a[i]=0;
            sb.append(a[i]+"\n");
        }
        System.out.print(sb);
    }
    static class Pair
    {
        int i,w;
        Pair(int a,int b)
        {
            i=a;
            w=b;
        }
    }
}
