import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class EhabandPatheticMEXs {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		String str = "";
		ArrayList<Integer> g[] = new ArrayList[n];
		int[] ans = new int[n];
		for (int i = 0; i < n; i++) {
			g[i] = new ArrayList<Integer>();
		}
		for (int i = 1; i < n; i++) {
			g[input.nextInt() - 1].add(i);
			g[input.nextInt() - 1].add(i);
		}
		for (int i = 0; i < n; ++i) {
			if (g[i].size() <= 2)
				continue;
			Arrays.fill(ans, -1);
			for (int j = 0; j < 3; ++j)
				ans[g[i].get(j)] = j;
			for (int k = 1, j = 3; k < n; ++k) {
				if (ans[k] < 0)
					ans[k] = j++;
				str += ans[k] + "\n";
			}
		}
		if (str.isEmpty())
			for (int i = 1; i < n; i++) {
				System.out.println(i - 1);
			}
		else
			System.out.println(str);
		input.close();
	}
}
