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

public class march_14_div2_628 {
	
	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out=new PrintWriter(System.out);
		int n=Integer.parseInt(br.readLine());
		int[][]arr=new int[n][2];
		int[]freq=new int[n];
		
		for(int i=0;i<n-1;i++) {
			String str=br.readLine();
			StringTokenizer st=new StringTokenizer(str);
			int u=Integer.parseInt(st.nextToken());
			int v=Integer.parseInt(st.nextToken());
			freq[u-1]++;freq[v-1]++;
			arr[i][0]=u;arr[i][1]=v;
		}
		int total=0;
		for(int i=0;i<n;i++) {
			if(freq[i]==1)
				total++;
		}
		int t=total;
		total=0;
		for(int i=0;i<n-1;i++) {
			if(freq[arr[i][0]-1]==1 || freq[arr[i][1]-1]==1)
				{out.println(total);total++;}
			else
			{out.println(t);t++;}
		}
		out.close();
	}
}
