import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        
        int n = in.nextInt(),u,v;
        int ans[] = new int[n-1];
        // int deg[] = new int[n];
        ArrayList<Integer> g[] = new ArrayList[n];
        for(int i=0;i<n;i++) g[i] = new ArrayList<>();
        for(int i=0;i<n-1;i++){
            u = in.nextInt()-1;
            v = in.nextInt()-1;
            g[u].add(i);
            g[v].add(i);
            // deg[u]++;deg[v]++;
            ans[i]=-1;
        }
        int ind = 0,mx = g[0].size();
        for(int i=1;i<n;i++){
            if(g[i].size() > mx){
                mx = g[i].size();
                ind = i;
            }
        }
        int cur=0;
        for(int i: g[ind]){
            ans[i]=cur++;
        }
        for(int i=0;i<n-1;i++){
            if(ans[i]==-1){
                ans[i]=cur++;
            }
            out.println(ans[i]);
        }
    }
    
    /************* SOLUTION ENDS HERE **********/
}