n = int(input())
deg = [0]*(n+2)
es = []
for i in range(n-1):
	a,b = list(map(int, input().split()))
	deg[a]+=1
	deg[b]+=1
	es.append((a,b))
if max(deg)==2:
	for i in range(n-1):
		print(i)
else:
	k = deg.index(max(deg))
	e_012 = 0
	cnt = 3
	for e in es:
		if k in e and e_012 < 3:
			print(e_012)
			e_012+=1
		else:
			print(cnt)
			cnt+=1
		
