out = [0] * 100020
order = []
count = 0
for _ in range(int(input()) - 1):
    x, y = map(int, input().split())
    out[x] += 1
    order.append((x, y))
for o in out:
    if o >= 3:
        count += 1
res1, res2 = 0, 0
if count > 0: res2 = 3
for x, y in order:
    if out[x] >= 3 and res1 <= 2: 
        print(res1)
        res1 += 1
    else:
        print(res2)
        res2 += 1