n = int(input())
a = [0] * (n - 1)
b = [0] * (n - 1)
ans = [-1] * (n - 1)
x = 0
for i in range(n-1):
    a[i] , b[i] = map(int,input().split())
for i in range(n-1):
    if b[i] not in a or a[i] not in b:
        ans[i] = x
        x += 1
    else:
        continue
for i in range(n-1):
    if ans[i] == -1:
        ans[i] = x
        x += 1
for i in range(n-1):
    print(ans[i])