# a single edge with 2 nodes will always take the smallest, distinct label
# which is any parent or child node that has appeared at most once
# for everything else, there's mastercard 
dic = {}; check = []
size = int(input())
for _ in range(size-1):
    a,b = map(int,input().split())
    check.append((a,b))
    if a not in dic.keys(): dic.update({a:1})
    else: dic[a] += 1
    if b not in dic.keys(): dic.update({b:1})
    else: dic[b] += 1
crat,trap = 0,size-2
for j,k in check:
    if dic[j] == 1 or dic[k] == 1:
        print(crat)
        crat+=1
    else:
        print(trap)
        trap-= 1
