
import java.util.*;
import java.io.*;
public class Dij
{
 static class Node
  {
	  int deg;
	  ArrayList<Integer> edge;
	  Node()
	  {
		 edge=new ArrayList();
		  deg=0;
	  }
  }
public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	int n=Integer.parseInt(br.readLine());
	int edge[]=new int[n];
	Node[] nodes=new Node[n];
	for(int i=0;i<n;i++)
		nodes[i]=new Node();
	
	int[] order=new int[n-1];
	for(int i=0;i<n-1;i++)
	{
		String inp[]=br.readLine().split(" ");
		int a=Integer.parseInt(inp[0])-1;
		int b=Integer.parseInt(inp[1])-1;
		nodes[a].deg++;
		nodes[b].deg++;
		nodes[a].edge.add(i);
		nodes[b].edge.add(i);
		
	}
	Arrays.sort(nodes,new Comparator<Node>() {
	public int compare(Node a,Node b)
	{
		return a.deg-b.deg;
	}});
	Arrays.fill(order,-1);
	int top=0;
	for(int i=0;i<n;i++)
	{
		if(nodes[i].deg==1)
		{
			int x=nodes[i].edge.get(0);
			if(order[x]==-1)
			order[x]=top++;
		}
	}
	for(int i=0;i<n-1;i++)
	{
		if(order[i]==-1)
		{
			order[i]=top++;
		}
	}
	StringBuilder sb=new StringBuilder();
	for(int i=0;i<n-1;i++)
		sb.append(order[i]+"\n");
	System.out.println(sb);
	
	}

}
