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

public class ehabAndPatheticMEXs {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int deg[] = new int[n + 1];
		edges ed[] = new edges[n - 1];
		for (int i = 0; i < n - 1; i++) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			ed[i] = new edges(u, v);
			deg[u]++;
			deg[v]++;
		}
//		Arrays.sort(ed);
		int edNo = 0;
		for (int i = 0; i < n - 1; i++) {
			if (deg[ed[i].u] > 2) {
				int j = i;
				while (j < n - 1 && ed[j].u == ed[i].u) {
					ed[j++].edgeNo = edNo++;
				}
				i = j;
			}
		}
		for (int i = 0; i < n - 1; i++) {
			if (deg[ed[i].u] <= 2) {
				ed[i].edgeNo = edNo++;
			}
		}
		for (int i = 0; i < n - 1; i++) {
			System.out.println(ed[i].edgeNo);
		}
	}
}

class edges implements Comparable<edges> {
	int u, v, edgeNo;

	edges(int u, int v) {
		this.u = u;
		this.v = v;
		edgeNo = -1;
	}

	@Override
	public int compareTo(edges o) {
		// TODO Auto-generated method stub
		return u - o.u;
	}
}