import sys 
import math
from collections import Counter

def IO():
	sys.stdin=open("pyinput.txt", 'r')
	sys.stdout=open("pyoutput.txt", 'w')

def GCD(a, b):
	if(b==0): return a
	else: return GCD(b, a%b)

def LCM(a, b): return a*(b//GCD(a, b))

def scan(TYPE_1, TYPE_2=0):
	if(TYPE_1==int):
		return map(int, sys.stdin.readline().strip().split())
	elif(TYPE_1==float):
		return map(float, sys.stdin.readline().strip().split())
	elif(TYPE_1==list and TYPE_2==float):
		return list(map(float, sys.stdin.readline().strip().split()))
	elif(TYPE_1==list and TYPE_2==int):
		return list(map(int, sys.stdin.readline().strip().split()))
	elif(TYPE_1==str):
		return sys.stdin.readline().strip()
	else: print("ERROR!!!!") 


cnt=0
vis=[0 for i in range(100008)]

def dfs(n):
	global vis, cnt

	if(vis[n]==1): return
	vis[n]=1
	
	for i in edge[n]:
		if(vis[i]==1): continue

		dfs(i)
		if(mp.get((n, i), -5)==-1): 
			mp[(n, i)]=cnt
		else:
			mp[(i, n)]=cnt
		cnt+=1


def main():
	
	n=int(scan(str))
	global edge
	edge=[[] for i in range(n+3)]
	global mp
	mp={}
	for i in range(n-1):
		a, b=scan(int)
		mp[(a, b)]=-1
		edge[a].append(b)
		edge[b].append(a)
	
	
	dfs(1)
	for i in mp:
		print(mp[i])

	

# IO()
main()