n=int(input())
graph=[0]*(n+1) 
li=[] 
val=[-1]*(n-1)
for _ in range(n-1):
    x,y=map(int,input().strip().split(' '))
    li.append([x,y])
    graph[x]+=1 
    graph[y]+=1   
count=0
for i in range(n-1):
    if graph[li[i][0]]==1 or graph[li[i][1]]==1:
        val[i]=count 
        count+=1 
for i in val:
    if i==-1:
        print(count)
        count+=1 
    else:
        print(i)

        
        