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!!!!") 



def main():
	
	n=int(input())
	a=[[] for i in range(n+3)]
	mp={}

	for i in range(n-1):
		u, v=scan(int)
		a[u].append(v), a[v].append(u)
		mp[(u, v)]=-1

	mx=-1
	idx=0

	for i in range(1, n+1):
		if(len(a[i])>mx):
			mx=len(a[i])
			idx=i

	cnt1=0
	cnt2=n-2

	for a,b in mp:
		if(a==idx or b==idx):
			print(cnt1)
			cnt1+=1
		else:
			print(cnt2)
			cnt2-=1


# IO()
main()