n = int(input())
rel = {}
_in = [0] * 10020
order = []
leaf = []

for _ in range(n - 1):
    x, y = map(int, input().split())
    _in[y] += 1
    order.append((x, y))
for x in _in:
    if x >= 2:
        order = [(y, x) for x, y in order]
        break
for x, y in order:
    try: rel[x].append(y)
    except: rel[x] = [y]
for i in range(1, n+1):
     if i not in rel.keys():
         leaf.append(i)
res1 = 0; res2 = n-2
for x, y in order:
    if y in leaf:
        print(res1)
        res1 += 1
    else:
        print(res2)
        res2 -= 1
