import math, sys
#q=int(input())
q=1
 
n = int(sys.stdin.readline())
lines = sys.stdin.readlines()
 
for _ in range(q):
    count=[0]*100005
    arr=[]
    for line in lines:
        a,b=map(int,line.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 
    print("\n".join(list(map(str, ans))))