
n = int(input())

from collections import defaultdict
d = {}
d1 = defaultdict(list)
ans = [None for i in range(n-1)]
flag = 0
for i in range(n-1):
	a,b = map(int,input().split())
	# d2[(a,b)] = i
	d[b] = (a,i)
	d1[a].append(b)
	if len(d1[a]) == 2 and a in d:
		flag = 1
		ans[d[a][1]] = 0
		ans[i-1] = 1
		ans[i] = 2
if flag == 1:
	j = 3
else:
	j = 0
i = 0
while i < len(ans):
	# print(i)
	if len(ans) > 2 and (ans[i] == 0 or ans[i] == 1 or ans[i] == 2):
		i = i + 1
		continue
	else:
		ans[i] = j
		j = j + 1
	i = i + 1
# print(ans)
for i in ans:
	print(i)