from sys import stdin, gettrace

if not gettrace():
    def input():
        return next(stdin)[:-1]


# def input():
#    return stdin.buffer.readline()

def main():
    n = int(input())
    adj = [[] for _ in range(n)]
    for i in range(n-1):
        u,v = map(int, input().split())
        adj[u-1].append((v-1, i))
        adj[v-1].append((u-1, i))
    next = 0
    res = [-1]*(n-1)
    for u in range(n):
        if len(adj[u]) == 1 and res[adj[u][0][1]] == -1:
            res[adj[u][0][1]] = next
            next+=1
            if next == 3:
                break
    for i in range(n-1):
        if res[i] == -1:
            res[i] = next
            next+=1
    print('\n'.join(map(str,res)))




if __name__ == "__main__":
    main()