import sys
input = sys.stdin.readline
n=int(input())
d=[0 for i in range(n)]
arr=[]
for _ in range(n-1):
    temp=[int(x) for x in input().split()]
    d[temp[0]-1]+=1
    d[temp[1]-1]+=1
    arr.append(temp)
maxi=d.index(max(d))
curr=0
dusra=max(d)
ans=[]
for i in range(n-1):
    if arr[i][0]-1==maxi or arr[i][1]-1==maxi:
        ans.append(curr)
        curr+=1
    else:
        ans.append(dusra)
        dusra+=1
for i in ans:
    print(i)