from sys import stdin, stdout
n=int(stdin.readline())
edges=[]
sz=[0]*(n+1)
ans=[-1]*(n-1)
for i in xrange(n-1):
    u,v=map(int, stdin.readline().split())
    edges.append([u,v,i])
    edges.append([v,u,i])
    sz[u]+=1
    sz[v]+=1

m=0

for i in xrange(len(sz)):
    if sz[i]>sz[m]:
        m=i

res=0
for i in xrange(len(edges)):
    if edges[i][0]==m:
        ans[edges[i][2]]=res
        res+=1

for i in xrange(len(edges)):
    if ans[edges[i][2]]==-1:
        ans[edges[i][2]]=res
        res+=1
print '\n'.join(map(str, ans))