from math import *
# from sys import stdin,stdout

def binarySearch(arr,x,i):
	l=i
	r=len(arr)-1 
	while l <= r: 
		mid = (l + r)//2; 
		if arr[mid] == x: 
			return mid 
		elif arr[mid] < x: 
			l = mid + 1
		else: 
			r = mid - 1
	return -1

def js(arr,x):
	l=0
	r=len(arr)-1
	ans=-1
	while(l<=r):
		m=(l+r)//2
		if(arr[m]<=x):
			ans=m
			l=m+1
		else:
			r=m-1
	return ans

def jg(arr,x,i):
	l=i
	r=len(arr)-1
	ans=-1
	while(l<=r):
		m=(l+r)//2
		if(arr[m]>=x):
			ans=m
			r=m-1
		else:
			l=m+1
	return ans

# def ceil(a,b):
# 	if a%b == 0:
# 		return int(a/b)
# 	else:
# 		return (a//b + 1)

n=int(input())
d=[0]*n
ans=[-1]*(n-1)
q=[]
for i in range(n-1):
	x,y=map(int,input().split())
	q.append([x-1,y-1])
	d[x-1]+=1
	d[y-1]+=1
c=0
for i in range(n-1):
	if(d[q[i][0]]==1):
		ans[i]=c
		c+=1
	else:
		if(d[q[i][1]]==1):
			ans[i]=c
			c+=1
for i in range(n-1):
	if(ans[i]==-1):
		ans[i]=c
		c+=1

for i in range(n-1):
	print(ans[i])
