from collections import Counter
import sys

reader = (tuple(map(int, line.split())) for line in sys.stdin)

am = int(input())
bran = list()
for i in range(am - 1):
    bran.append(next(reader))

num_barn = enumerate(bran)


result = []
c = Counter()
for br in bran:
    c[br[0]] += 1
    c[br[1]] += 1
i = 0
best = c.most_common(1)[0]
if best[1] >= 3:
    for br in num_barn:
        if br[1][0] == best[0] or br[1][1] == best[0]:
            result.append((br[0], i))
            i += 1
            if len(result) >= 3:
                break
for j in range(0, am - 1):
    if len(result) != 0 and result[0][0] == j:

        print(result[0][1])
        # print(result)
        result.pop(0)
    else:
        print(i)
        i += 1