import java.util.*;
import java.io.*;
 
 
public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	static StringBuilder sb = new StringBuilder();
	static List<Integer>[] adj;
	static List<Integer> ans = new ArrayList<>();
	static int N;
	
	
    public static void main(String[] args) throws Exception {
    	N = Integer.parseInt(br.readLine());
    	adj = new ArrayList[N+1];
    	for(int i=1; i<=N; i++) adj[i] = new ArrayList<>();
    	int u=0,v=0;
    	for(int i=0; i<N-1; i++) {
    		st = new StringTokenizer(br.readLine());
    		u = Integer.parseInt(st.nextToken());
    		v = Integer.parseInt(st.nextToken());
    		ans.add(v);
    		adj[u].add(v);
    	}
    	int first = 0, last = N-2;
    	int node=0;
    	for(int i=0; i<N-1; i++) {
    		node = ans.get(i);
    		if(adj[node].size()==0) {
    			sb.append(first).append("\n");
    			first++;
    		}
    		else {
    			sb.append(last).append("\n");
    			last--;
    		}
    	}
    	System.out.println(sb);
    }
}