n = int(input())
lst = [0] * (n+1)
s = []
for i in range(n-1):
    a, b = map(int, input().split())
    s.append((a,b))
    lst[a]+=1
    lst[b] +=1

sol = []
left = 0
right = n-2
for a, b in s:
    if lst[a] == 1 or lst[b] == 1:
        print(left)
        left +=1
    else:
        print(right)
        right -=1

