n=int(input())
c=[0]*(100005)
arr=[]
for i in range(n-1):
    a,b=map(int,input().split())
    c[a]+=1
    c[b]+=1
    arr.append([a,b])
ans=[]
x=0
y=n-2
for i in range(len(arr)):
    if c[arr[i][0]]==1 or c[arr[i][1]]==1:
        ans.append(x)
        x+=1
    else:
        ans.append(y)
        y-=1
for i in range(len(ans)):
    print(ans[i])