import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
edge=[]
D=[0]*n
for i in range(n-1):
  u,v=map(int,input().split())
  edge.append((u,v))
  D[u-1]+=1
  D[v-1]+=1
if max(D)<=2:
  for i in range(n-1):
    print(i)
else:
  Ans=[-1]*(n-1)
  for i in range(n):
    if D[i]>=3:
      c=i
      break
  rest=3
  for i in range(n-1):
    u,v=edge[i]
    if rest:
      if u-1==c or v-1==c:
        Ans[i]=rest-1
        rest-=1
  cur=3
  for i in range(n-1):
    if Ans[i]!=-1:
      print(Ans[i])
    else:
      print(cur)
      cur+=1

