import functools
n=int(input())
g=[]
for _ in range(n):
    g.append(set())
el=[]
d={}
freq={}
for j in range(n-1):
    u,v=map(int,input().split())
    u-=1
    v-=1
    el.append((min(u,v),max(u,v)))
    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=n-2
while curr>=0:
    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)
        
    


    
