n=int(input())
if n==2:
    print(0)
    exit()
E=[[] for _ in range(n)]
E_=[0]*n
ans=[-1]*(n-1)
for i in range(n-1):
    a,b=map(int,input().split())
    E[a-1].append([b-1,i])
    E[b-1].append([a-1,i])
    E_[a-1]+=1
    E_[b-1]+=1
if max(E_)<=2:
    x=0
    for i in range(n):
        if E_[i]==1:
            ans[E[i][0][1]]=x
            x+=1
    for i in range(n-1):
        if ans[i]==-1:
            ans[i]=x
            x+=1
else:
    for i in range(n):
        if E_[i]>=3:
            ans[E[i][0][1]]=0
            ans[E[i][1][1]]=1
            ans[E[i][2][1]]=2
            break
    x=3
    for i in range(n-1):
        if ans[i]==-1:
            ans[i]=x
            x+=1
for i in range(n-1):
    print(ans[i])