n=int(input())
graph={}
for i in range(n):
    graph[i+1]=[]
edges=[]
for i in range(n-1):
    a,b=map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
    edges.append([a,b])
big=0
node=0
for i in range(n):
    if len(graph[i+1])>2:
        node=i+1
        big=1
if big==0:
    counter=0
    for i in range(n-1):
        print(counter)
        counter+=1
else:
    counter=3
    counter2=0
    for i in edges:
        if i[0]==node or i[1]==node:
            if counter2<3:
                print(counter2)
                counter2+=1
            else:
                print(counter)
                counter+=1
        else:
            print(counter)
            counter+=1