import sys
def main():
    n = int(sys.stdin.readline())
    adj = [[] for i in range(n)]
    st = 0
    d = dict()
    for i in range(n-1):
        u,v = [int(j)-1 for j in sys.stdin.readline().split()]
        d[(u,v)] = "#" 
        adj[u].append(v)
        adj[v].append(u)
        if len(adj[u])>2:
            st = u
        elif len(adj[v])>2:
            st = v
    stack = [st]
    ct = 0
    visited = set()
    while(len(stack)>0):
        # print(stack)
        v = stack.pop()
        visited.add(v)
        # print(v)
        # break
        for nb in adj[v]:
            if nb not in visited:
                if (nb,v) in d:
                    d[(nb,v)] = str(ct)
                    ct+=1
                elif (v,nb) in d:
                    d[(v,nb)] = str(ct)
                    ct+=1
                stack.append(nb)
    sys.stdout.write("\n".join(list(d.values())))
main()