import sys
from collections import defaultdict
n=int(sys.stdin.readline())
graph=defaultdict(list)
rem=[]
for _ in range(n-1):
    u,v=map(int,sys.stdin.readline().split())
    graph[u].append(v)
    graph[v].append(u)
    rem.append([min(u,v),max(u,v)])
l=[]
for i in graph:
    l.append([len(graph[i]),i])
l.sort()
#l.reverse()
vis=defaultdict(lambda:-1)
count=0
#print(graph,'graph')
#print(l,'l')
for i in range(len(l)-1,-1,-1):
    node=l[i][1]
    for j in range(len(graph[node])):
        a,b=min(graph[node][j],node),max(graph[node][j],node)
        if vis[(a,b)]==-1:
            vis[(a,b)]=count
            count+=1
for i,j in rem:
    print(vis[(i,j)])
