n = int(input())
a = []
b = dict()
num = '1'
for i in range(n - 1):
    a.append(input().split())
    if a[i][0] in b:
        b[a[i][0]] += 1
    else:
        b[a[i][0]] = 1
    if a[i][1] in b:
        b[a[i][1]] += 1
    else:
        b[a[i][1]] = 1
    if b[a[i][1]] == 3:
        num = a[i][1]
    if b[a[i][0]] == 3:
        num = a[i][0]
k = 0
count = 0
count2 = 3
for i in range(n - 1):
    if (num in a[i]) and (k < 3):
        print(count)
        count += 1
        k += 1
    else:
        print(count2)
        count2 += 1

