t=int(input())
count=[0]*100005
a=[]
for j in range(t-1):
    
    x1,x2=map(int,input().split())
    count[x1]+=1 
    count[x2]+=1 
    a.append([x1,x2]) 
k=0 
l=t-2
# print(count[:5])
# print(a)
ans =[]
for i in range(len(a)):
    if count[a[i][0]]==1 or count[a[i][1]]==1 :
        # print(a[i][0],a[i][1])
        ans.append(k)
        k+=1 
    else:
        # print(a[i][0],a[i][1])

        ans.append(l)
        # print(ans)
        l-=1 
for i in range(len(ans)):
    print(ans[i])
    
    
    
    
    
    