n = int(input())
categories_to_nodes = {0: {i for i in range(1,n+1)}, 1: set(), 2:set()}

all_data = []
for edge in range(n-1):
    data = input().split()
    all_data.append(data)
    if int(data[0]) in categories_to_nodes[0]:
        categories_to_nodes[0].remove(int(data[0]))
        categories_to_nodes[1].add(int(data[0]))
    elif int(data[0]) in categories_to_nodes[1]:
        categories_to_nodes[1].remove(int(data[0]))
        categories_to_nodes[2].add(int(data[0]))

    if int(data[1]) in categories_to_nodes[0]:
        categories_to_nodes[0].remove(int(data[1]))
        categories_to_nodes[1].add(int(data[1]))
    elif int(data[1]) in categories_to_nodes[1]:
        categories_to_nodes[1].remove(int(data[1]))
        categories_to_nodes[2].add(int(data[1]))

leaves = categories_to_nodes[1]
if len(leaves) == 2:
    for i in range(n-1):
        print(i)
else:
    i=n-2
    j=0
    for data in all_data:
        if int(data[0]) in leaves or int(data[1]) in leaves:
            print(j)
            j+=1
        else:
            print(i)
            i-=1
