import sys
n=int(input())
data=sys.stdin.readlines()
g=[[] for i in range(n)]
ribs=dict()
for i in range(n-1):
    v,u=map(int,data[i].split())
    v-=1
    u-=1
    ribs[frozenset([v,u])]=i
    g[v].append(u)
    g[u].append(v)
answer=[-1] *(n-1)
count=0
for v in range(n):
    if len(g[v])==1:
        answer[ribs[frozenset([v,g[v][0]])]]=count
        count+=1
for i in range(n-1):
    if answer[i]==-1:
        answer[i]=count
        count+=1
print(*answer,sep="\n")

