n = int(input())
degree = [0] * (n + 1)
order = []
for _ in range(n-1):
    x, y = map(int, input().split())
    degree[x] += 1
    degree[y] += 1
    order.append((x, y))
res1 = 0; res2 = n-2
for x, y in order:
    if degree[x] >= 3 or degree[y] >= 3:
        print(res1)
        res1 += 1
    else:
        print(res2)
        res2 -= 1