n=int(input())
l=[]
freq=[0]*(n+1)
for _ in range(n-1):
    l1=list(map(int,input().split()))
    freq[l1[0]]+=1
    freq[l1[1]]+=1
    l.append(l1)
s,e=0,n-2
ans=[]
for l1 in l:
    if freq[l1[0]]==1 or freq[l1[1]]==1:
        ans.append(s)
        s+=1
    else:
        ans.append(e)
        e-=1
for i in ans:
    print(i)