from collections import Counter
import string
import math
import sys
def array_int():
    return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variables):
    if arrber_of_variables==1:
        return int(sys.stdin.readline())
    if arrber_of_variables>=2:
        return map(int,sys.stdin.readline().split()) 
def makedict(var):
    return dict(Counter(var))
mod=1000000007
#i am noob wanted to be better and trying hard for that
n=vary(1)
graph=[0 for i in range(n+1)] 
values=[]
for i in range(n-1):
    u,v=vary(2)
    values.append([u,v])
    graph[u]+=1
    graph[v]+=1
st=0
fn=n-2
for i in values:
    if graph[i[0]]>1:
        print(st)
        st+=1
    else:
        print(fn)
        fn-=1





        







    


            
        


        

   





    
        






    


            


        

        
        




    











            
        


        






                 

            
    

















        






        


        



