''' Ehab and Path-etic MEXs - spoiled by mzy
'''




''' routine '''


N = int(input())
leaves = {}
edges = [0 for i in range(N)]
for edge in range(N - 1):
    a, b = list(map(int, input().split()))
    for node in (a, b):
        edges[node - 1] += 1
        if edges[node - 1] == 1:
            leaves[node] = edge
        elif edges[node - 1] == 2:
            del leaves[node]

if len(leaves) < 3:
    for n in range(N - 1):
        print(n)
else:
    start = 3
    leaf = 0
    specials = list(leaves.values())[:3]
    for edge in range(N - 1):
        if edge in specials:
            print(leaf)
            leaf += 1
        else:
            print(start)
            start += 1
    # print(specials)