n = int(input())
a = [0]*n
pos = -1
c = []
for i in range(0, n-1):
    u, v = map(int, input().split())
    c.append([u, v])
for i in range(0, n-1):
    a[c[i][0]-1] += 1
    a[c[i][1]-1] += 1
    if a[c[i][0]-1] >= 3:
        pos = c[i][0]
        break
    if a[c[i][1]-1] >= 3:
        pos = c[i][1]
        break
ans = [-1]*(n-1)
count = 3
if pos != -1:
    for i in range(0, n-1):
        if c[i][0] == pos or c[i][1] == pos:
            ans[i] = (count-1)
            count -= 1
            if count == 0:
                break
count = 3
if pos == -1:
    count -= 3
for i in range(0, n-1):
    if ans[i] == -1:
        ans[i] = count
        count += 1
for i in range(0, n-1):
    print(ans[i])