lis=[]
n=int(input())

dic={}
approve=-1
for i in range(n-1):
    
    a,b=map(int,input().split())
    lis.append([a,b])
    dic[a]=dic.get(a,0)+1
    dic[b]=dic.get(b,0)+1
    if dic[a]==3 and approve==-1:
        approve=a
        
start=0
start2=3

if approve==-1:
    for i in lis:
        print(start)
        start+=1
else:
    for i in lis:
        if i[0]==approve or i[1]==approve:
            print(start)
            start+=1 
        else:
            print(start2)
            start2+=1
        