class Node:
	def __init__(self,a):
		self.data = a
		self.left = None
		self.right = None

t = int(input())
root = None
d = set()
for i in range(t-1):
	# d = {}
	a,b = map(int,input().split())
	if root == None:
		root = Node(a)
		d.add(a)
		root.left = Node(b)
		temp = root

		continue
	if temp.data == a:
		if not temp.left:
			temp.left = Node(b)
		else:
			temp.right = Node(b)
	if temp.left.data == a:
		temp = temp.left
		temp.left = Node(b)
	elif temp.right.data == a:
		temp = temp.right
		temp.left = Node(b)

	if not temp.left:
		temp.left = Node(b)
	else:
		temp.right = Node(b)
temp = (root,-1)
stack = [temp]
# print(root.data)
# print(root.left)
c = -1
while stack:
	# print(stack)
	temp = stack.pop()
	if temp[0].left:
		c = c + 1
		stack.append((temp[0].left,c))
		print(c)
	if temp[0].right:
		c = c + 1
		stack.append((temp[0].right,c))
		print(c)

