n=int(input())
present=[0]*(n+1)
l=[]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    present[a]+=1
    present[b]+=1
    l.append([a,b])
s=0
m=n-2
for a,b in l:
    if present[a]==1 or present[b]==1:
        print(s)
        s+=1
    else:
        print(m)
        m-=1
    