from sys import stdin 
from collections import defaultdict 
import operator 






N = int(input())
vertex = defaultdict(lambda:[])
zz = False 
edges = []
for _ in range(N - 1):
	u, v = map(int, stdin.readline().split())
	vertex[u].append(v)
	vertex[v].append(u)
	edges.append((u, v))




three_node = False 
for v in vertex.keys():
	if len(vertex[v]) >= 3:
		three_node = True
		mark = v 

if three_node:
	c = 0
	other = 3
	for i in range(N - 1):
		u, v = edges[i]
		if mark in (u, v) and c <= 2:
			print (c)
			c += 1
		else:
			print (other)
			other += 1 
else:
	for i in range(N - 1):
		print (i)