import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class C628_C {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		int n = Integer.parseInt(br.readLine());
		
		int[][] edges = new int[n-1][2];
		int[] count = new int[n+1];
		
		for(int i = 0; i<n-1; i++) {
			String[] temp = br.readLine().split(" ");
			int a = Integer.parseInt(temp[0]);
			int b = Integer.parseInt(temp[1]);
			count[a] ++;
			count[b] ++;
			edges[i][0] = a;
			edges[i][1] = b;
		}
		int root = -1;
		int how = 0;
		for(int i = 1; i<n+1; i++) {
			if(count[i] >=3) {
				root = i;
				how = count[i];
				break;
			}
		}
		
		if(root == -1) {
			for(int i = 0; i<n-1; i++) {
				bw.write(i+"\n");
			}
		}
		else {
			int other = n-1;
			int these = how-1;
			for(int i = 0; i<n-1; i++) {
				if(edges[i][0] != root && edges[i][1] != root) {
					bw.write(other+"\n");
					other--;
				}
				else {
					bw.write(these+"\n");
					these--;
				}
			}
		}
		

		bw.flush();
		br.close();
		bw.close();
	}

	
}
