
n = int(input())

links = [set([]) for i in range(n)]
paths = []

for i in range(n-1):
  In,Out = input().split(' ')
  links[int(In)-1].add(i)
  links[int(Out)-1].add(i)

out = [0]*(n-1)
k=0
links.sort(key=len)

done = set([])
for i in range(n-1):
  for j in links[i]:
    if j not in done:
      done.add(j)
      out[j] = str(k)
      k+=1

for i in out:
  print(i)  
