nodes = {}

if __name__ == '__main__':
    numNodes = int(input())
    nodes = {}
    mentioned = {}
    for i in range(1,numNodes+1):
        nodes[i] = set()
        mentioned[i] = []

    for _ in range(numNodes-1):
        edge = input().split(" ")
        mentioned[int(edge[0])].append(_)
        mentioned[int(edge[1])].append(_)
        nodes[int(edge[0])].add(int(edge[1]))
        nodes[int(edge[1])].add(int(edge[0]))
    
    triplet = -1
    for i in range(1,numNodes+1):
        if (len(mentioned[i]) >= 3):
            triplet = mentioned[i][:3]
    count = 3
    tripCount = 0
    if (triplet == -1):
        for i in range(numNodes-1):
            print(i)
    else:
        for i in range(numNodes-1):
            if i not in triplet:
                print(count)
                count += 1
            else:
                print(tripCount)
                tripCount += 1

"""6
1 2
1 3
2 4
2 5
5 6"""