from sys import stdin,stdout
from math import gcd,sqrt
from collections import deque
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
S=lambda:input().rstrip('\n')
L=lambda:list(R())
P=lambda x:stdout.write(x)
lcm=lambda x,y:(x*y)//gcd(x,y)
hg=lambda x,y:((y+x-1)//x)*x
pw=lambda x:1 if x==1 else 1+pw(x//2)
chk=lambda x:chk(x//2) if not x%2 else True if x==1 else False
sm=lambda x:(x**2+x)//2
N=10**9+7
n=I()
v=[[] for i in range(n)]
val=[0]*n
ln=[0]*n
p=0
for i in range(n-1):
	x,y=R()
	v[x-1]+=i,
	v[y-1]+=i,
	ln[x-1]+=1
	ln[y-1]+=1
for i in range(n):
	if ln[i]>=3:
		val[v[i][0]]=1
		val[v[i][1]]=2
		val[v[i][2]]=3
		p=3
		break
for i in range(n-1):
	if val[i]:print(val[i]-1)
	else:print(p);p+=1