n = int(input())
edge_count = [0]*100001
edge_list = []
for _ in range(n-1):
	u,v = map(int,input().split())
	edge_count[u]+=1
	edge_count[v]+=1
	edge_list.append([u,v])

min_val,max_val = 0,n-2
edge_weight = []
for i in range(len(edge_list)):
	if edge_count[edge_list[i][0]]==1 or edge_count[edge_list[i][1]] == 1:
		edge_weight.append(min_val)
		min_val+=1
	else:
		edge_weight.append(max_val)
		max_val-=1

for weight in edge_weight:
	print(weight)