
//package codeforce;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
 
 
public class submit {
    public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		ArrayList<Integer> arl[] = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			arl[i] = new ArrayList<>();
		}
		for (int i = 0; i < n - 1; i++) {
			String s = br.readLine();
			String[] ss = s.trim().split(" ");
			int x = Integer.parseInt(ss[0]) - 1;
			int y = Integer.parseInt(ss[1]) - 1;
			arl[x].add(i);
			arl[y].add(i);
		}
		int flag = 0;
		int[] ans = new int[n - 1];
		HashSet<Integer> set = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			if (arl[i].size() > 2) {
				flag = 1;
				ans[arl[i].get(0)] = 0;
				ans[arl[i].get(1)] = 1;
				ans[arl[i].get(2)] = 2;
				set.add(arl[i].get(0));
				set.add(arl[i].get(1));
				set.add(arl[i].get(2));
				break;
			}
		}
		if (flag == 0) {
			for (int i = 0; i < n - 1; i++) {
				System.out.println(i);
			}
		} else {
			int k = 3;
			for (int i = 0; i < n - 1; i++) {
				if (!set.contains(i))
					ans[i] = k++;
				System.out.println(ans[i]);
			}
		}
    }
}
