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
for i in range(1,n):
    for j in range(1,len(vec[i])):
#        print(i,vec[i][j])
        if d[(i,vec[i][j])]==-1:
            d[(i,vec[i][j])]=c
            c+=1
for i in d:
    print(d[i])            



