n = int(input())
vec=[[] for i in range(n+1)]
d={}
li=[-1]*(n-1)
for i in range(n-1):
    a,b = map(int,input().split())
    vec[a].append([b,i])
    vec[b].append([a,i])
    d[(a,b)]=0
#print(vec)
mx = max([len(vec[i]) for i in range(n)])
c=0
for i in range(n):
    if len(vec[i])>2:
        for j in vec[i]:
            li[j[1]]=c
            c+=1
        break
#    print(li)    
for i in range(n):
    for j in vec[i]:
        if li[j[1]]==-1:
            li[j[1]]=c
            c+=1
for i in li:
    print(i)









