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

public class EhabandPatheticMEXs {
	 // https://codeforces.com/contest/1325/problem/C
	
	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("EhabandPatheticMEXs.in"));
		// INPUT //

		int n = Integer.parseInt(in.readLine());  
		int[] vertex1 = new int[n-1];
		int[] vertex2 = new int[n-1];
		
		int[] count = new int[n+1]; // this will count how many times that
			// vertex is passed
			// ignore 0 index
		
		int max = 0;
		int vertex_max = 0;
		
		for (int i = 0; i < n-1; i++) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			vertex1[i] = Integer.parseInt(st.nextToken());  
			vertex2[i] = Integer.parseInt(st.nextToken()); 
			
			count[vertex1[i]]++;
			count[vertex2[i]]++;
		}
		
		for (int i = 1; i < count.length; i++) {
			if (count[i] > max) {
				max = count[i];
				vertex_max = i;
			}
		}
		
		int vertex_max_pointer = 0;
		int other_pointer = n - max;
		
		for (int i = 0; i < n-1; i++) {
			if (vertex1[i] == vertex_max || vertex2[i] == vertex_max) {
				System.out.println(vertex_max_pointer);
				vertex_max_pointer++;

			}
			else {
				System.out.println(other_pointer);
				other_pointer++;
			}
		}

	}

}

/*
	I think that once you find the vertex that is connected to the most edges,
		you can rotate around that vertex and give it the values
			from 0 to however many edges it has -1. then the rest don't matter.


*/
