n = int(input())
 
edges = []
neighbs = [0 for i in range(n)]
 
for i in range(n - 1):
    u, v = map(int, input().split())
    edges.append((u, v))
    neighbs[u - 1] += 1
    neighbs[v - 1] += 1
 
low_next = 0
high_next = n - 2
 
for u, v in edges:
    if neighbs[u - 1] == 1 or neighbs[v - 1] == 1:
        print(low_next)
        low_next += 1
    else:
        print(high_next)
        high_next -= 1
        