from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
def solve():
	a=0
	b=n-2
	for i in l:
		if len(dx[i[0]])==1 or len(dx[i[1]])==1:
			print(a)
			a+=1
		else:
			print(b)
			b-=1
	# return ans

n=int(input())
dx={i:set() for i in range(1,n+1)}
d={i:set() for i in range(1,n+1)}
l=[]
for i in range(n-1):
	a,b=map(int,input().split())
	dx[a].add(b)
	dx[b].add(a)
	l.append([a,b])
# stack=[1]
# while stack:
# 	a=stack.pop()
# 	for i in dx[a]:
# 		d[a].add(i)
# 		stack.append(i)
# 		dx[i].remove(a)
solve()