import functools,sys
def ip():
    
    n=int(sys.stdin.readline())
    g=[]
    for _ in range(n):
        g.append(set())
    d={}
    for j in range(n-1):
        u,v=map(int,sys.stdin.readline().split())
        u-=1
        v-=1
        d[(min(u,v),max(u,v))]=j
        g[u].add(v)
        g[v].add(u)
    k=[i for i in range(n)]
    def myfun(u,v):
        return len(g[u])-len(g[v])
    k=sorted(k,key=functools.cmp_to_key(myfun))
    ans=[0]*(n-1)
    curr=0
    #print(k)
    while curr<n-1:
        if len(k)==0:
            break
        u=k.pop()
        if len(g[u])==0:
            continue
        while g[u]:
            v=g[u].pop()
            g[v].remove(u)
            t=(min(u,v),max(u,v))
            ans[d[t]]=curr
            curr+=1
    for i in ans:
        print(i)
ip()
            
        


    
