import java.util.*;
import java.math.*;
public class Main {
	final static int maxn=(int)1e5+10;
	static int a[]=new int [maxn];
	static int b[]=new int [maxn];
	static Vector<Integer>vec[]=new Vector[maxn];
	static int ind[]=new int [maxn];
 public static void main(String args[])
 {
	 Scanner input=new Scanner(System.in);
	int n=input.nextInt();
	int maxsize=-1;int index=-1;
	for(int i=1;i<=n-1;i++)
	{
		int x,y;
		x=input.nextInt();y=input.nextInt();
		a[i]=x;b[i]=y;
		ind[x]++;ind[y]++;
		if(ind[x]>maxsize)
		{
			index=x;maxsize=ind[x];
		}
		if(ind[y]>maxsize)
		{
			index=y;maxsize=ind[y];
		}
	}
	
	if(n==2)
		System.out.println(0);
	else
	{
	if(maxsize==2)
	{
		for(int i=1;i<=n-1;i++)
			System.out.println(i-1);
	}
	else if(maxsize>=3) 
	{
		int cnt=3;
		for(int i=1,j=4;i<=n-1;i++)
		{
			if(a[i]!=index&&b[i]!=index||cnt==0)
				{System.out.println(j-1);j++;}
			else
			{
				if(cnt==3)
				{
					System.out.println(0);cnt--;
				}
				else if(cnt==2)
				{
					System.out.println(1);cnt--;
				}
				else if(cnt==1)
				{
					System.out.println(2);cnt--;
				}
			}
		}
	}
 }
}
}