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


for i in d:
    print(d[i])            



