import sys
input=sys.stdin.buffer.readline

# t=int(input())

# for _ in range(t):
n=int(input())
nodes={i:0 for i in range(1,n+1)}
# arr=[int(c) for c in input().split()]
q=[]
needednode=-1
for i in range(n-1):
    a,b=[int(c) for c in input().split()]
    q.append((a,b))
    nodes[a]+=1
    if nodes[a] >=3:
        needednode=a
    nodes[b]+=1
    if nodes[b] >=3:
        needednode=b

if needednode == -1:
    for i in range(len(q)):
        print(i)
else:
    first=0
    second=3
    for a,b in q:
        if first <  3 and  (a==needednode or b == needednode):
                print(first)
                first+=1
        else:
            print(second)
            second+=1
    

