def listint():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])-1
    return a

def main():
    n = int(input())
    graph = []
    for i in range(n-1):
        graph.append(listint())
    nodes = []
    for i in range(n):
        nodes.append(0)
    for i in range(n-1):
        nodes[graph[i][0]] = nodes[graph[i][0]] +1
        nodes[graph[i][1]] = nodes[graph[i][1]] +1
    ans = []
    for i in range(n-1):
        ans.append(-1)
    for i in range(n):
        if nodes[i] >= 3:
            p = 0
            for j in range(n-1):
                if graph[j][0] == i:
                    ans[j] = p
                    p = p+1
                if graph[j][1] == i:
                    ans[j] = p
                    p = p+1
            for j in range(n-1):
                if ans[j] == -1:
                    ans[j] = p
                    p = p+1
            return ans
    for i in range(n-1):
        ans[i] = i
    return ans
ans = main()
for i in range(len(ans)):
    print(ans[i])