n = int(input())
a = [0] * (n)
b = [0] * (n)
c = [0] * (n + 1)
d = [-1] * (n + 1)
for i in range(n - 1):
    a[i], b[i] = map(int, input().split())
    c[a[i]] += 1
    c[b[i]] += 1
ok = 0
k = 0
for i in range(1, n + 1):
    if c[i] > 2:
        ok = 1
        for j in range(n - 1):
            if a[j] == i or b[j] == i:
                d[j] = k
                k += 1
        break
    
for j in range(n - 1):
    if d[j] == -1:
        print(k)
        k += 1
    else:
        print(d[j])
   
