def answer(nodeCount, nodeRelationship) :
    graph = [0 for i in range(nodeCount)]
    labelStickers = [i for i in range(len(nodeRelationship), 2, -1)]
    smallLabelStickers = [0, 1, 2]
    labels = [-1 for i in range(len(nodeRelationship))]

    for i in range(len(nodeRelationship)) :
        graph[nodeRelationship[i][0]-1] += 1
        graph[nodeRelationship[i][1]-1] += 1

    for i in range(len(graph)) :
        if graph[i] >= 3 :
            nodeIndex = i+1
            for j in range(len(nodeRelationship)) :
                nr = nodeRelationship[j]
                if (nr[0] == nodeIndex or nr[1] == nodeIndex) and len(smallLabelStickers) > 0 :
                    labels[j] = smallLabelStickers.pop()
                else :
                    labels[j] = labelStickers.pop()
            break
    else :
        labels = labelStickers + smallLabelStickers[0:1]
    
    return labels

nodeCount = int(input())
nodeRelationship = [0 for i in range(nodeCount-1)]
for i in range(nodeCount-1) :
    nodeRelationship[i] = list(map(int, input().split()))

for label in answer(nodeCount, nodeRelationship) :
    print(label)