import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
import java.math.BigInteger.*;
import java.util.Arrays; 

public class   Iloveweselyleung1
{
  BufferedReader in;
  StringTokenizer as;
  int  nums[],nums2[];
    Map<Integer,Integer > map = new HashMap<Integer, Integer>();
  ArrayList < Integer >  ar[];
    ArrayList < Integer >  ar2 = new ArrayList < Integer >();
  public static void main (String[] args)
  {
    new Iloveweselyleung1  ();
  }
  
    int findGCD(int number1, int number2) {
        if(number2 == 0){
            return number1;
        }
        return findGCD(number2, number1%number2);
    }
  
  
  public Iloveweselyleung1  ()
  {
    try
    {
      
      in = new BufferedReader (new InputStreamReader (System.in));
      int a = nextInt();
      ar = new ArrayList[a];
      for(int x = 0;x<a;x++)
        ar[x] = new ArrayList < Integer >();
      for(int x = 0;x<a-1;x++)
      {
        int b = nextInt()-1;
        int c = nextInt()-1;
        ar[b].add(c);
        ar[b].add(x);
        ar[c].add(b);
        ar[c].add(x);
      }
      for(int x = 0;x<a;x++)
      {
        if(ar[x].size() == 2)
        {
          ar2.add(ar[x].get(1));
          if(ar2.size() == 3)
            break;
        }
      }
      if(ar2.size() != 3)
      {
        for(int x = 0;x<a-1;x++)
          System.out.println(x);
      }
      else
      {
        int count = 3;
        int count1 = 0;
        for(int x = 0;x<a-1;x++)
        {
          if(x != ar2.get(0) && x != ar2.get(1) && x != ar2.get(2)) 
          {
            System.out.println(count);
            count++;
          }
          else
          {
            System.out.println(count1);
            count1++;
          }
        }
      }
     
    }
    
    
    
    catch(IOException e)
    {
      System.out.println(e);
      
    }
  }
  String next () throws IOException
  {
    while (as == null || !as.hasMoreTokens ())
    {
      as = new StringTokenizer (in.readLine ().trim ());
    }
    
    
    return as.nextToken ();
  }
  
  
  
  long nextLong () throws IOException
  {
    return Long.parseLong (next ());
  }
  
  
  int nextInt () throws IOException
  {
    return Integer.parseInt (next ());
  }
  
  
  double nextDouble () throws IOException
  {
    return Double.parseDouble (next ());
  }
  
  
  String nextLine () throws IOException
  {
    return in.readLine ().trim ();
  }
}