


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


public class graph1 { 
	


	public static void main(String[] args) throws IOException {
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		 ArrayList<Integer>[] arr = new ArrayList[t+1]; 
	     int n=t;
	     // initializing 
	     for (int i = 1; i <= t; i++) { 
	         arr[i] = new ArrayList<Integer>(); 
	     } 
	     LinkedHashMap<String,Integer> jj=new LinkedHashMap<>();
	     for(int i=0;i<n-1;i++) {
	     	int a=s.nextInt();
	     	int b=s.nextInt();
	     	arr[a].add(b);
	     	arr[b].add(a);
	     	jj.put(a+" "+b, 0);
	     }
	     int count=n-2;
	     
	    for(String hh:jj.keySet()) {
	    	int temp=Integer.parseInt(hh.split(" ")[1]);
	    	if(arr[temp].size()>2) {
	    		jj.put(hh, count);
	    		count--;
	    	}
	    }
	    for(String hh:jj.keySet()) {
	    	int temp=Integer.parseInt(hh.split(" ")[1]);
	    	if(arr[temp].size()==2) {
	    		jj.put(hh, count);
	    		count--;
	    	}
	    }
	    for(String hh:jj.keySet()) {
	    	int temp=Integer.parseInt(hh.split(" ")[1]);
	    	if(arr[temp].size()==1) {
	    		jj.put(hh, count);
	    		count--;
	    	}
	    }
	     for(int g:jj.values()) {
	    	 System.out.println(g);
	     }


	} }

