if __name__=="__main__":
	n=int(input())
	if n==2:
		print(0)
		exit(0)
	lis=[0]*(n+1)
	link=[0]*(n+1)
	prt=[3]*(n-1)
	for i in range(n-1):
		x,y=(int(m) for m in input().split())
		link[x]=link[y]=i
		lis[x]+=1
		lis[y]+=1
	
	pt=lis.index(1)
	prt[link[pt]]=1
	pt=lis.index(1,pt+1)
	prt[link[pt]]=0
	if lis.count(1)>2:
		prt[link[lis.index(1,pt+1)]]=2
	k=n-2
	for i in prt:
		if i>2:
			print(k)
			k=k-1
		else:
			print(i)