n=int(input())
dic={}
ar=[]
for i in range(1,n+1):
    dic[i]=0
for i in range(n-1):
    a,b=map(int,input().split())
    dic[a]+=1
    dic[b]+=1
    ar.append([a,b])
sta=0
end=n-2
for y,z in ar:
    if(dic[y]==1 or dic[z]==1):
        print(sta)
        sta+=1
    else:
        print(end)
        end-=1
        