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

public class Solution{
	public static void main (String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out=new PrintWriter(System.out);
		String[] temp=br.readLine().trim().split(" ");
		int n=Integer.parseInt(temp[0]);
		int[][] edges=new int[n-1][2];
		int[] degree=new int[n+1];
		for(int i=0;i<n-1;i++){
		    temp=br.readLine().trim().split(" ");
		    int u=Integer.parseInt(temp[0]);
		    int v=Integer.parseInt(temp[1]);
		    degree[u]++;
		    degree[v]++;
		    edges[i][0]=u;
		    edges[i][1]=v;
		}
		int count=0;
		int[] ans=new int[n-1];
		for(int i=0;i<n-1;i++){
		    int u=edges[i][0];
		    int v=edges[i][1];
		    if(degree[u]==1 || degree[v]==1)
		    {
		        ans[i]=count;
		        count++;
		    }
		}
		for(int i=0;i<n-1;i++){
		    int u=edges[i][0];
		    int v=edges[i][1];
		    if(degree[u]>1 && degree[v]>1){
		        ans[i]=count;
		        count++;
		    }
		}
		for(int i=0;i<n-1;i++){
		    out.println(ans[i]);
		}
		out.flush();
		out.close();
	}
}