from sys import stdin

n = int(stdin.readline())
link_dic = {}

link_list = []
link_time = [0 for i in range(n)]

for i in range(n - 1):
    x, y = map(int, stdin.readline().split())
    link_time[x-1] += 1
    link_time[y-1] += 1
    link_list.append([x, y])
spe_index = 0
ord_index = n - 2
for x, y in link_list:
    if link_time[x-1] == 1 or link_time[y-1] == 1:
        print(spe_index)
        spe_index += 1
    else:
        print(ord_index)
        ord_index -= 1