

def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    counts = [0]*N
    edges = []
    for _ in range(N-1):
        edge = read_ints()
        edge[0] -= 1
        edge[1] -= 1
        edges.append(edge)
        counts[edge[0]] += 1
        counts[edge[1]] += 1
    C = 0
    labels = [-1]*(N-1)
    for i, (u, v) in enumerate(edges):
        if counts[u] == 1 or counts[v] == 1:
            labels[i] = C
            C += 1
    for i in range(N-1):
        if labels[i] == -1:
            labels[i] = C
            C += 1
    for label in labels:
        print(label)


if __name__ == '__main__':
    solve()
