n = int(input())
# nodes: 1, ...n
# edge: 0, 1, ... n-2
nodes = [[] for _ in range(n+2)]
for i in range(n-1):
    a, b = [int(x) for x in input().split()]
    nodes[a].append(i)
    nodes[b].append(i)

max_node = max(range(1, n+1), key=lambda x: len(nodes[x]))
ans = [None]*(n-1)
cur = 0
for i in nodes[max_node]:
    ans[i] = cur
    cur+=1

for i in range(n-1):
    if ans[i] is None:
        ans[i] = cur
        cur += 1
print('\n'.join([str(x) for x in ans]))
