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

public class Solution{
    public static void main(String[] args){
        Scanner in =new Scanner(System.in);
        int t = 1;
        while(t-->0){
            int n=in.nextInt();
            int[] a=new int[n];
            cnt = 0;
            ans= new HashMap<>();
            LinkedList<Integer>[] g=new LinkedList[100005];
            int start = -1;
            int[] us= new int[n-1];
            int[] vs = new int[n-1];
            for(int i=0;i<n-1;i++){
                int u=in.nextInt();
                int v=in.nextInt();
                if (start==-1)start = u;
                if(g[u]==null){
                    g[u]=new LinkedList<>();
                }
                if(g[v]==null){
                    g[v]=new LinkedList<>();
                }
                g[u].add(v);
                g[v].add(u);
                us[i] =Math.min(u,v);
                vs[i] =Math.max(u,v);
            }
            int[] vis = new int[n+1];
            dfs(start,g,vis,-1);
            for(int i=0;i<n-1;i++){
                System.out.println(ans.get(getKey(us[i],vs[i])));
            }
        }
    }
    
    static long cnt;
    static HashMap<Long,Long> ans;
    
    public static void dfs(int st,LinkedList<Integer>[] g,int[] vis, int par){
        if(vis[st]==1)return;
        for(int next:g[st]){
            if(next==par)continue;
            ans.put(getKey(st,next),cnt);
            cnt++;
            dfs(next,g,vis,st);
        }
        vis[st]=1;
    }
    
    public static long getKey(int a,int b){
        return (long)1000000007*Math.min(a,b)+Math.max(a,b);
    }
    
    
}