N = int(input())
edges = []
in_node = [0]*N

for _ in range(N-1):
    a, b = map(int, input().split())
    in_node[a-1] += 1
    in_node[b-1] += 1
    edges.append([a-1, b-1])
leaf = {i for i, v in enumerate(in_node) if v == 1}

num = 0
ids = [-1]*(N-1)
for i in range(N-1):
    a, b = edges[i]
    if a in leaf or b in leaf:
        ids[i] = num
        num += 1
for i in range(N-1):
    a, b = edges[i]
    if ids[i] == -1:
        ids[i] = num
        num += 1
print("\n".join(map(str, ids)))
