def main():
    n = int(input())
    order = []
    tree = {}
    for i in range(1,n+1):
        tree[i] = []

    edges = {}
    for i in range(n-1):
        u,v = map(int,input().split())
        tree[u].append(v)
        tree[v].append(u)
        order.append((u,v))
    
    found = False
    for i in tree.keys():
        if len(tree[i]) >= 3:
            found = True
            node = i
            break

    ans = []
    if not found:
        for i in range(n-1):
            ans.append(i)
    else:
        curr = n-2
        count = 0
        while order:
            u,v = order.pop(0)
            if count < 3:
                if u == node or v == node:
                    ans.append(count)
                    count += 1
                else:
                    ans.append(curr)
                    curr -= 1
            else:
                ans.append(curr)
                curr -= 1

    for i in ans:
        print(i)


main()
