//package r628;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class third {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int used = -1;
		HashMap<String,int[]> hm = new HashMap<String,int[]>();
		int[] parent = new int[n+1];
		int children[] = new int[n+1];
		int uv[][] = new int[n-1][2];
		for(int i =0;i<n-1;i++)
		{
			int u = sc.nextInt();
			int v = sc.nextInt();
			uv[i][0] = Math.min(u, v);
			uv[i][1] = Math.max(u, v);
			hm.put(uv[i][0]+" "+uv[i][1],new int[]{i,-1});
			parent[uv[i][1]] = uv[i][0];
			children[uv[i][0]]+=1;
		}
		for(int i =1;i<n+1;i++)
		{
			if(children[i]==0)
			{
				String s = parent[i]+" "+i;
				//System.out.print(s);
				int[] val = hm.get(s);
				val[1] = ++used;
				hm.put(s, val);
			}
			
		}
		for(String s : hm.keySet())
		{
			int val[] = hm.get(s);
			if(val[1]==-1)
			{
				val[1] = ++used;
			}
			hm.put(s, val);
		}
		for(int i =0;i<n-1;i++)
		{
			String s = uv[i][0]+" "+uv[i][1];
			System.out.println(hm.get(s)[1]);
		}
		
		

	}

}
