from collections import Counter

vertexes_number = int(input())
edges = Counter()

ledger = []
for _ in range(vertexes_number - 1):
    _from, to = map(int, input().split())
    ledger.append((_from, to))
    edges[_from] += 1
    edges[to] += 1

(vertex, power), = edges.most_common(1)
if power >=3:
    asc_index = 0
    desc_index = vertexes_number - 2
    for index, (_from, to) in enumerate(ledger):
        if _from == vertex or to == vertex:
            print(asc_index)
            asc_index += 1
        else:
            print(desc_index)
            desc_index -= 1
else:
    for index in range(len(ledger)):
        print(index)