n=int(input())
a=[[] for i in range(n+1)]
ind=0
d={}
h={}
import sys 
for _ in range(n-1):
	x,y=map(int,sys.stdin.readline().split())
	d[(min(x,y),max(x,y))]=-1
	h[(min(x,y),max(x,y))]=_
	
	a[x].append(y)
	a[y].append(x)
	if len(a[x])>2:
		ind=x
	if len(a[y])>2:
		ind=y
		

vis=[0]*(n+1)
ans=[i for i in range(n-1)]
if ind!=0:
	c=0
	for j in a[ind]:
		d[(min(j,ind),max(j,ind))]=c
		c+=1
	for j in d:
		if d[j]==-1:
			ans[h[j]]=c
			c+=1
		else:
			ans[h[j]]=d[j]
for i in ans:
	print(i)				
		
	
