from sys import stdin,stdout
import sys
from bisect import bisect_left,bisect_right
import heapq
from collections import Counter
# sys.setrecursionlimit(2*(10**5))

# stdin = open("input.txt", "r");
# stdout = open("output.txt", "w");


n=int(stdin.readline().strip())

adj=[[] for i in range(n)]

for i in range(n-1):
	u,v=stdin.readline().strip().split(' ')
	u,v=int(u),int(v)
	u-=1;v-=1
	adj[u].append((v,i))
	adj[v].append((u,i))

ctr=0
ans=[-1 for i in range(n-1)]
adj=sorted(adj,key= lambda x: (len(x)),reverse=True)
for i in adj:
	for j in i:
		if ans[j[1]]==-1:
			ans[j[1]]=ctr
			ctr+=1
#print(adj)

for i in ans:
	stdout.write(str(i)+"\n")
