n = int(input())

v = [[] for i in range(n)]
ans = [-1 for i in range(n)]

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

mx = [0, 0]
for i in range(n):
    mx = max(mx, [len(v[i]), i])

cur = 0
for i in v[mx[1]]:
    ans[i] = cur
    cur += 1

for i in range(n-1):
    if ans[i] == -1:
        ans[i] = cur
        cur += 1
    print(ans[i])