import java.util.*;

public final class Mex {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++) {
			nodes[i] = new Node();
			nodes[i].next = new Node[n];
		}
		int[] order1 = new int[n - 1];
		int[] order2 = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			order1[i] = sc.nextInt() - 1;
			order2[i] = sc.nextInt() - 1;
			nodes[order1[i]].next[nodes[order1[i]].count] = new Node();
			nodes[order1[i]].next[nodes[order1[i]].count++] = nodes[order2[i]];
			nodes[order2[i]].next[nodes[order2[i]].count] = new Node();
			nodes[order2[i]].next[nodes[order2[i]].count++] = nodes[order1[i]];
		}
		int[] leaf = new int[3];
		int leafCount = 0;
		for (int j = 0; leafCount < 3 && j < n; j++) {
			if(nodes[j].count == 1) {
				leaf[leafCount++] = j;
			}
		}
		int other = leafCount;
		for (int i = 0; i < n - 1; i++) {
			if(order1[i] == leaf[0] || order1[i] == leaf[1] || order1[i] == leaf[2] || order2[i] == leaf[0] || order2[i] == leaf[1] || order2[i] == leaf[2])
				System.out.println(--leafCount);
			else
				System.out.println(other++);
		}
	}
}

class Node {
	Node[] next;
	int count = 0;
}