n=int(input())
e = [[] for _ in range(n+1)]
ec = [0 for _ in range(n+1)]
done = False
for i in range(n-1):
    a,b=map(int,input().split())
    if done: continue
    e[a].append(i)
    e[b].append(i)
    ec[a]+=1
    ec[b]+=1
    soll = []
    if ec[a]>=3:
        soll = e[a]
        done = True
    elif ec[b]>=3:
        soll = e[b]
        done = True
if not done:
    for i in range(n-1):
        print(i)
else:
    x=0
    y=3
    for i in range(n-1):
        if i in soll:
            print(x)
            x+=1
        else:
            print(y)
            y+=1