n = int(input())
graph = [[] for _ in range(n)]
edges = []
for _ in range(n-1):
    a, b = map(int, input().split())
    a = a - 1
    b = b - 1
    edges.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
count = 0
c = 0
ans = {}
for edge in edges:
    if len(graph[edge[0]]) == 1 or len(graph[edge[1]]) == 1:
        ans[edge] = c
        c += 1
for edge in edges:
    if edge not in ans:
        ans[edge] = c
        c += 1
    print(ans[edge])
