import sys
sys.setrecursionlimit(200000)
LI=lambda:list(map(int, sys.stdin.readline().strip('\n').split()))
MI=lambda:map(int, sys.stdin.readline().strip('\n').split())
SI=lambda:sys.stdin.readline().strip('\n')
II=lambda:int(sys.stdin.readline().strip('\n'))

n=II()
tree={i:[] for i in range(n+1)}
vis=[False]*(n+1)
edges=[]
mex={}
m=0
for __ in range(n-1):
	u, v=MI()
	edges.append([u, v])
	tree[u].append(v)
	tree[v].append(u)
s=sorted(tree, key=lambda c:len(tree[c]), reverse=True)
for u in s[:-1]:
	for v in tree[u]:
		if mex.get((u, v), -1)==-1 or mex.get((v, u), -1)==-1:
			mex[(u, v)]=mex[(v, u)]=m
			m+=1
for u, v in edges:
	print(mex[u, v])