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])
    edges.append([v,u])
    sz[u]+=1
    sz[v]+=1

m=0

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

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

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