import java.util.*;
import java.io.*;

public class C1325 {
	
	static int n;
	static TreeSet<Integer>[] adjList;
	static boolean[] vis;
	static int counter;
	static TreeMap<Pair, Integer> map;
	
	/*public static int dfs(int u) {
		vis[u] = true;
		for(int v : adjList[u]) {
			if(!vis[v]) {
				int x = dfs(v);
				int min = Math.min(u, v), max = Math.max(u, v);
				map.put(new Pair(min, max), x);
			}
		}
		return ++counter;
	}*/

	public static void main(String[] args) throws IOException {
		//Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st;
		
		n = Integer.parseInt(br.readLine());
		adjList = new TreeSet[n];
		for(int i = 0; i < n; i++)
			adjList[i] = new TreeSet<Integer>();
		int[][] store = new int[n - 1][2];
		for(int i = 0; i < n - 1; i++) {
			st = new StringTokenizer(br.readLine());
			int u = Integer.parseInt(st.nextToken()) - 1, v = Integer.parseInt(st.nextToken()) - 1;
			adjList[u].add(v);
			adjList[v].add(u);
			store[i][0] = u;
			store[i][1] = v;
		}
		
		if(n == 2) {
			pw.println("0");
			pw.flush();
			return;
		}
		
		Queue<Integer> qu = new LinkedList<>();
		for(int i = 0; i < n; i++)
			if(adjList[i].size() == 1)
				qu.add(i);
		counter = 0;
		map = new TreeMap<>();
		while(qu.size() > 1) {
			int x = qu.poll();
			int y = adjList[x].pollFirst();
			adjList[y].remove(x);
			int min = Math.min(x, y), max = Math.max(x, y);
			map.put(new Pair(min, max), counter);
			counter++;
			if(adjList[y].size() == 1)
				qu.add(y);
		}
		/*
		int maxV = 0, x = 0;
		for(int i = 0; i < n; i++)
			if(adjList[x].size() > maxV) {
				maxV = adjList[x].size();
				x = i;
			}
		
		vis = new boolean[n];
		counter = n - 1;
		dfs(x);
		*/
		
		for(int i = 0; i < n - 1; i++) {
			int min = Math.min(store[i][0], store[i][1]), max = Math.max(store[i][0], store[i][1]);
			pw.println(map.get(new Pair(min, max)));
		}
		
		pw.flush();
	}
	
	public static class Pair implements Comparable<Pair> {
		int i, j;
		
		public Pair(int i, int j) {
			this.i = i;
			this.j = j;
		}
		
		public int compareTo(Pair p) {
			if(this.j == p.j)
				return this.i - p.i;
			return this.j - p.j;
		}
	}
}

