n = int(input())

if n == 2:
    a, b = [int(i) for i in input().split()]
    print(0)
    exit(0)

r = [[] for i in range(n - 1)]
K = [0 for i in range(n)]
for i in range(n - 1):
    a, b = [int(i) for i in input().split()]
    r[i] = [a - 1, b - 1]
    K[a - 1] += 1
    K[b - 1] += 1

s = set()
for i in range(len(K)):
    if K[i] == 1:
        s.add(i)
        if len(s) > 3:
            break

k = 0
if len(s) <= 2:
    l = 2
    f = 2
else:
    l = 3
    f = 3
for a, b in r:
    if (a in s or b in s) and k < f:
        print(k)
        k += 1
    else:
        print(l)
        l += 1
