from sys import stdin
try:
    n=int(stdin.readline().rstrip())
    l=[0]*(n+1)
    arr=[]
    for _ in range(n-1):
        u,v=map(int,stdin.readline().rstrip().split())
        arr.append((u,v))
        l[u]+=1
        l[v]+=1
    x,y=0,n-2
    for u,v in arr:
        if l[u]==1 or l[v]==1:
            print(x)
            x+=1
        else:
            print(y)
            y-=1
except:
    pass