import math
#q=int(input())
q=1
for _ in range(q):
    n=int(input())
    count=[0]*100005
    arr=[]
    for i in range(n-1):
        a,b=map(int,input().split())
        count[a]+=1 
        count[b]+=1 
        arr.append([a,b])
    ans=[]
    u=0 
    v=n-2
    for i in range(len(arr)):
        if count[arr[i][0]]==1 or count[arr[i][1]]==1:
            ans.append(u)
            u+=1 
        else:
            ans.append(v)
            v-=1 
    for i in range(len(ans)):
        print(ans[i])