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())

	d[(a,b)] = i
	d1[a].append(b)
	d1[b].append(a)
	if len(d1[a]) == 3 and flag == 0:

		if (a,d1[a][0]) in d:
			ans[d[(a,d1[a][0])]] = 0
		else:
			ans[d[(d1[a][0],a)]] = 0
		if (a,d1[a][1]) in d:
			ans[d[(a,d1[a][1])]] = 1
		else:
			ans[d[(d1[a][1],a)]] = 1
		if (a,d1[a][2]) in d:
			ans[d[(a,d1[a][2])]] = 2
		else:
			ans[d[(d1[a][2],a)]] = 2
		flag = 1
	if len(d1[b]) == 3 and flag == 0:
		if (b,d1[b][0]) in d:
			ans[d[(b,d1[b][0])]] = 0
		else:
			ans[d[(d1[b][0],b)]] = 0
		if (b,d1[b][1]) in d:
			ans[d[(b,d1[b][1])]] = 1
		else:
			ans[d[(d1[b][1],b)]] = 1
		if (b,d1[b][2]) in d:
			ans[d[(b,d1[b][2])]] = 2
		else:
			ans[d[(d1[b][2],b)]] = 2
		flag = 1
i = 0
if flag == 1:
	j = 3
else:
	j = 0
while i < len(ans):
	if ans[i] == None:
		ans[i] = j
		j = j + 1

	i = i + 1
for i in ans:
	print(i)
