n=int(input())
deg=[0]*n
neigh=[0]*n
for i in range(n-1):
    u,v=map(int,input().split())
    deg[u-1]+=1
    deg[v-1]+=1
    neigh[u-1]=i
    neigh[v-1]=i
if n==2:
    print(0)
else:
    if max(deg)==2:
         #print(*range(n-1))
         for i in range(n-1):
             print(i)

    else:
        p=[-1]*(n-1)
        s=0
        for i in range(n):
            if deg[i]==1:
                p[neigh[i]]=s
                s+=1
        for i in range(n-1):
            if p[i]==-1:
                p[i]=s
                s+=1
        #print(*p)
        for i in range(n-1):
            print(p[i])