# t=int(input())
# for _ in range(t):
n=int(input())
a=[]
g=[]
dic={}

for i in range(n):
	g.append([])
for i in range(n-1):
	u,v=map(int,input().split())
	a.append((u-1,v-1))

	g[u-1].append(v-1)
	g[v-1].append(u-1)

s=0
# print(g)
for i in range(len(g)):
	# print(len(g[i]))
	if(len(g[i])>=3):
		# print(i)
		u=i
		s=0
		for v in g[i]:
			dic[(u,v)]=s
			dic[(v,u)]=s

			s+=1
		break
# print(dic)
if(s==0):
	for i in range(n-1):
		print(i)
else:
	# print(s)
	for i in a:
		if i in dic:
			print(dic[i])
		else:
			print(s)
			s+=1






