import java.util.*;
import java.io.*;
import java.util.concurrent.TimeUnit;

public class patheticMEX {
    
	public static void main (String [] args) throws Exception {
	    BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	    int N = Integer.parseInt(f.readLine());
	    List<List<Integer>> adjList = new ArrayList<>();
	    for(int i = 0; i < N+1; i++) {
	    	adjList.add(new ArrayList<>());
	    }
	    for(int i = 1; i < N; i++) {
	    	StringTokenizer st = new StringTokenizer(f.readLine());
	    	int n1 = Integer.parseInt(st.nextToken());
	    	int n2 = Integer.parseInt(st.nextToken());
	    	adjList.get(n1).add(n2);
	    	adjList.get(n2).add(n1);
	    }
	    	    
	    int count = 1;
	    int[] arr = new int[N+1];
	    for(int i = 1; i < adjList.size(); i++) {
	    	if(adjList.get(i).size() == 1) {
	    		arr[i] = count;
	    		count++;
	    	}
	    }
	    
	    //System.out.println(Arrays.toString(arr));
	    
	    for(int i = 2; i < N+1; i++) {
	    	if(arr[i] == 0) {
	    		arr[i] = count;
	    		count++;
	    	}
	    }
	    
	    for(int i = 2; i < N+1; i++) {
	    	out.println(arr[i]-1);
	    }
	    
	    out.close();
	    f.close();
	}
	
}