n = int(input())
import collections
adj = collections.defaultdict(list)
#queue = collections.deque()
edges = []
for i in range(n - 1):
	a = [int(x) for x in input().split()]
	adj[a[0]].append(a[1])
	adj[a[1]].append(a[0])
	edges.append((a[0], a[1]))
#	start = a[0]

output = {}
id = 0
edges_set = set(edges)
#print (edges)
for k in list(adj.keys()):
	if len(adj[k]) == 1:
		#print (adj[k])
		if (k , adj[k][0]) in edges_set:
			output[(k , adj[k][0])] = id
			id += 1
		else:
			output[(adj[k][0], k)] = id
			id += 1
#print (output)
s = ""
for edge in edges:
	if edge in output:
		s += str(output[edge]) + "\n"
	else:
		s += str(id) + "\n"
		id += 1
print (s)
