N=int(input())
FA=[0]*N
edges=[]
for n in range(N-1):
    edges.append(list(map(int,input().split())))
    FA[edges[n][0]-1]+=1 
    FA[edges[n][1]-1]+=1 
leaf={} 
for i in range(N):
    if FA[i]==1:
        leaf.update({i+1:1}) 
val=0 
ans=[]
for e in edges:
    if e[0] in leaf.keys() or e[1] in leaf.keys():
        ans.append(val) 
        val+=1 
    else:
        ans.append(-1) 
for i in range(N-1):
    if ans[i]==-1:
        ans[i]=val 
        val+=1
for i in range(N-1):
    print(ans[i])
