from sys import stdin,stdout
import sys
from collections import Counter


n=int(stdin.readline().strip())

graph=[[] for i in range(n)]

for i in range(n-1):
	u,v=stdin.readline().strip().split(' ')
	u,v=int(u),int(v)
	u-=1;v-=1
	graph[u].append((v,i))
	graph[v].append((u,i))

gino=0
ans=[-1 for i in range(n-1)]
graph=sorted(graph,key= lambda x: (len(x)),reverse=True)
for i in graph:
	for j in i:
		if ans[j[1]]==-1:
			ans[j[1]]=gino
			gino+=1


for i in ans:
	stdout.write(str(i)+"\n")