#from overwrite_builtin_input import input

from collections import deque


def DFS(node):
    is_multi = len(paths[node]) > 1
    if node == 1 and len(paths[node]) < 3:
        is_multi = False
    for child in paths[node]:
        i = queue.popleft() if is_multi else queue.pop()
        index[(node, child)] = i
        DFS(child)


n = int(input())
edges = []
assigned_index = [-1] * (n - 1)
queue = deque(maxlen=n)
index = {}
for i in range(0, n-1):
    queue.append(i)

paths = {i: [] for i in range(1, n+1)}

for i in range(n - 1):
    a = [int(x) for x in input().split()]
    edge = a[0], a[1]
    if a[1] < a[0]:
        edge = a[1], a[0]
    edges.append(edge)
    index[edge] = i
    paths[edge[0]].append(edge[1])

DFS(1)

for edge in edges:
    print(index[edge])