n=input()
al=[[] for i in xrange(n+1)]
ans=[-1]*(n-1)
for i in xrange(n-1):
    u,v=map(int, raw_input().split())
    al[u].append([v, i])

m=0
res=0
for i in xrange(n+1):
    m=max(m, len(al[i]))

for i in xrange(len(al[m])):
    ans[al[m][i][1]]=res
    res+=1

for i in xrange(n+1):
    for j in xrange(len(al[i])):
        if ans[al[i][j][1]]==-1:
            ans[al[i][j][1]]=res
            res+=1

res=''
for i in xrange(n-1):
    res+=str([i])+'\n'
print res
