n = int(input())
a = [[] for x in range(n)]
e = []
bl = [0] * n
cnt = 1
if n == 2:
    print(0)
    exit()

for i in range(n - 1):
    boof1, boof2 = map(int, input().split())
    boof1 -= 1
    boof2 -= 1
    a[boof1].append(boof2)
    a[boof2].append(boof1)
    e.append((boof1, boof2))



for i in range(n):
    if len(a[i]) == 1:
        bl[i] = cnt
        cnt += 1

cnt2 = cnt
for i in range(n - 1):
    if bl[e[i][0]] != 0 or bl[e[i][1]] != 0:
        print(bl[e[i][0]] + bl[e[i][1]] - 1)
    else:
        print(cnt2 - 1)
        cnt2 += 1