n = int(input())

graph = {}
edges = [-1] * (n - 1)

for i in range(n - 1):
    src, dst = map(int, input().split())
    src -= 1
    dst -= 1
    graph.setdefault(src, [])
    graph.setdefault(dst, [])
    graph[src].append((dst, i))
    graph[dst].append((src, i))

i = 0
j = n - 2
use_i = False

def dfs(graph, v, edges, visited):
    global i, j, use_i
    visited.add(v)
    while graph[v]:
        w, ei = graph[v].pop()
        if w not in visited and edges[ei] == -1:
            if use_i:
                edges[ei] = i
                i += 1
            else:
                edges[ei] = j
                j -= 1
            use_i = not use_i
            dfs(graph, w, edges, visited)


visited = set()
dfs(graph, 0, edges, visited)

for mark in edges:
    print(mark)
