n=int(input())
adj_list=[[] for _ in range(n)];intial_arr=[]
for _ in range(n-1):
   a,b=map(int,input().split())
   #print('he')
   intial_arr.append([a-1,b-1])
   adj_list[a-1].append(b-1)
   adj_list[b-1].append(a-1)
l=0;ans={}
for i in range(n):
   if len(adj_list[i])>=3:
     for k in adj_list[i]:
      # print(ans)
       ans[(k,i)]=l
       ans[(i,k)]=l
       l+=1
       break
for a in intial_arr:
 # print('k')     
  if (a[0],a[1]) in ans:
      print(ans[(a[0],a[1])])
  elif (a[1],a[0]) in ans:
       print(ans[(a[1],a[0])])
  else:print(l);l+=1

  
       
      
