from sys import stdout
n=int(input())
a=[[] for i in range(n)]
e=[]
for _ in range(n-1):
    u,v=map(int,input().split())
    a[u-1].append(v-1)
    a[v-1].append(u-1)
    e.append([u-1,v-1])
ans=[-1]*(n-1)
k=0
for i in range(n-1):
    if len(a[e[i][1]])==1 or len(a[e[i][0]])==1:
        ans[i]=k
        k+=1
for i in range(n-1):
    if ans[i]==-1:
        ans[i]=k
        k+=1
for i in ans:
    stdout.write(str(i)+'\n')

