def run():
    n = int(input())
    edges = []
    graph = dict({i: 0 for i in range(1, n+1)})
    for _ in range(n-1):
        u, v = map(int, input().split())
        edges.append((u, v))
        graph[u] += 1
        graph[v] += 1
        if graph[u] >= 3 or graph[v] >= 3:
            if graph[u] >= 3:
                k = u 
            elif graph[v] >= 3:
                k = v
            h = 0
            l = graph[k]
            for e in edges:
                if e[0] == k or e[1] == k:
                    print(h)
                    h += 1
                else:
                    print(l)
                    l += 1
            return 
        
    for i in range(n-1):
        print(i)

run()