n=int(input())
g=[[] for i in range(n+1)]
edges=[]
for i in range(n-1):
	x,y=map(int,input().split())
	g[x].append([y,i])
	g[y].append([x,i])
c=0
indexes=[-1]*(n-1)
for l in g:
	if len(l)==1 and indexes[l[0][1]]==-1:
		indexes[l[0][1]]=c
		c+=1

for i in range(len(indexes)):
	if indexes[i]==-1:
		indexes[i]=c
		c+=1
	print(indexes[i])
