n = int(input())

graf = dict()
ucka = []
vcka = []


pocty = n * [0]
for i in range(n-1):
    [u, v] = [int(x) for x in input().split()]

    ucka.append(u)
    vcka.append(v)

    pocty[u-1] += 1
    pocty[v-1] += 1

hrana = None

if max(pocty)>2:
    for i in range(n):
        if pocty[i]>2:
            hrana = i+1
            break

spodne = 0
akt = 3

if hrana == None:
    for i in range(n-1):
        print(i)
else:
    for i in range(n-1):
        if (ucka[i] == hrana or vcka[i] == hrana) and spodne <3:
            print(spodne)
            spodne = spodne + 1
        else:
            print(akt)
            akt = akt+1
            
