n = int(input())
a = []
f = [0]*(n+1)
for i in range(n-1):
    fff = list(map(int, input().split()))
    fff.sort()
    a.append(fff)
    f[fff[0]] += 1
    f[fff[1]] += 1
ind = -1
mx = -1
for i in range(n):
    if f[i] > mx:
        mx = f[i]
        ind = i
i = 0
j = mx
ans = []
for k in a:
    if k[0] == ind or k[1] == ind:
        ans.append(i)
        i += 1
    else:
        ans.append(j)
        j += 1
for k in ans:
    print(k)