#                                               |
#   _` |  __ \    _` |   __|   _ \   __ \    _` |   _` |
#  (   |  |   |  (   |  (     (   |  |   |  (   |  (   |
# \__,_| _|  _| \__,_| \___| \___/  _|  _| \__,_| \__,_|

import sys
import math
from collections import defaultdict 

def read_line():
	return sys.stdin.readline()[:-1]
 
def read_int():
	return int(sys.stdin.readline())
 
def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

class Graph: 
  
	# Constructor 
	def __init__(self): 
  
		# default dictionary to store graph 
		self.graph = defaultdict(list) 
  
	# function to add an edge to graph 
	def addEdge(self, u, v): 
		self.graph[u].append(v) 
  
	# A function used by DFS 
	def DFSUtil(self, v, visited,val): 
		visited[v] = True
		for i in self.graph[v]: 
			if visited[i] == False: 
				d[(v,i)] = val%(n-1)
				val = self.DFSUtil(i, visited,val+2)
		return val
  
	def DFS(self, v,n): 
		visited = [False] *n 
		self.DFSUtil(v, visited,0) 

n = read_int()
g = Graph() 
d = {}
for i in range(n-1):
	u,v =read_int_line()
	d[(u-1,v-1)] = 0
	g.addEdge(u-1,v-1)


if n==3:
	print(0)
	print(1)
else:
	g.DFS(0,n)
	l = list(d.values())
	for i in range(n-1):
		print(l[i])


