
data = input().rstrip().split()
n = int(data[0])

edges = []

g = {i+1: [] for i in range(n)}

leafes = set()

for _ in range(n-1):
    data = input().rstrip().split()
    a, b = int(data[0]), int(data[1])
    a, b = sorted([a, b])
    edges.append((a, b))
    g[a].append(b)
    g[b].append(a)

for k, v in g.items():
    if len(leafes) == 3:
        break

    if len(v) == 1:
        e = sorted([k, v[0]])
        leafes.add(tuple(e))

counter = len(leafes)
l_counter = 0
to_print = []

for edge in edges:
    a, b = edge

    if edge in leafes:
        to_print.append(l_counter)
        l_counter += 1

    else:
        to_print.append(counter)
        counter += 1

for p in to_print:
    print(p)
