n = int(raw_input())
edges = []
weights = [0 for i in range(n+1)]
for i in range(n-1):
	a, b = map(int, raw_input().split())
	#a, b = i+1, i+2
	weights[a-1]+=1
	weights[b-1]+=1
	edges.append([a-1, b-1, -1])
for i in range(n-1):
	edges[i][1] = min(weights[edges[i][0]], weights[edges[i][1]])
	edges[i][0] = i
edges.sort(key = lambda x: x[1])
for i in range(n-1):
	edges[i][2] = i
edges.sort(key = lambda x:x[0])
for i in range(n-1):
	print(edges[i][2])