import sys

input = sys.stdin.readline
print = sys.stdout.write
# fin = open('input.txt', 'r')
# input = fin.readline

freqs = [0] * 100001
up_index = 0
down_index = 0


def make_number(edge):
    global down_index
    global up_index
    global freqs

    if freqs[edge[0]] == 1 or freqs[edge[1]] == 1:
        num = down_index
        down_index += 1
        return num
    num = up_index
    up_index += 1
    return num


def solve():
    global freqs
    global up_index

    n = int(input())
    lines = sys.stdin.readlines()
    edges = [tuple(map(int, line.split())) for line in lines]
    for edge in edges:
        freqs[edge[0]] += 1
        freqs[edge[1]] += 1
    down_nodes = [node for node in range(n + 1) if freqs[node] == 1]
    start_up_count = len(down_nodes)
    up_index = start_up_count
    ans = '\n'.join([str(make_number(edge)) for edge in edges])
    print(ans)


solve()