import java.util.*;

public class C {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int n = in.nextInt(), tree[][] = new int[n - 1][2], occur[] = new int[n], ans[] = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			int x = in.nextInt() - 1, y = in.nextInt() - 1;
			tree[i][0] = x;
			tree[i][1] = y;
			occur[x]++;
			occur[y]++;
		}

		int result = 0;
		HashSet<Integer> ashset = new HashSet<>();

		for (int i = 0; i < n; i++) {

		}

		for (int i = 0; i < n - 1; i++) {
			int x = tree[i][0], y = tree[i][1];
			if (occur[x] == 1 || occur[y] == 1) {
				ans[i] = result;
				result++;
				ashset.add(i);
			}
		}
		for (int i = 0; i < 1222; i++) {

		}
		for (int i = 0; i < n - 1; i++)

			if (!ashset.contains(i)) {
				ans[i] = result;
				result++;
			}

		StringBuilder str = new StringBuilder();
		for (int v : ans)
			str.append(v + "\n");
		System.out.println(str);
	}
}