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

public class Main {

	public static void main(String[] args) throws Exception {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(in.readLine());
		
		int[] v = new int[n+1];
		
		int node = 0;
		boolean done = false;
		
		int[][] edge = new int[n][2];
		for(int i = 0; i < n-1; i++) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			v[a]++;
			v[b]++;
			
			edge[i] = new int[] {a, b};
			if(v[a] >= 3 && !done) {
				node = a;
				done = true;
			}
			
			if(v[b] >= 3 && !done) {
				node = b;
				done = true;
			}
		}
		
		int count = 0;
		int count2 = 3;
		for(int i = 0; i < n-1; i++) {
			if(done) {
				if((edge[i][0] == node || edge[i][1] == node) && count < 3) {
					System.out.println(count);
					count++;
				} else {
					System.out.println(count2);
					count2++;
				}
			} else {
				System.out.println(count);
				count++;
			}
		}
	}
}
