n=int(input())
el=[]
deg=[0]*(n+1)
edge={}
ans_edge={}
for _ in range(n-1):
    u,v=map(int,input().split())
    el.append((u,v))
    deg[u]+=1 
    deg[v]+=1
    if u not in edge:
        edge[u]=set()
    if v not in edge:
        edge[v]=set()
    edge[u].add(el[-1])
    edge[u].add(el[-1])
ll=[(deg[i],i) for i in range(1,n)]
ll.sort(reverse=True)
val=0
#print(ll)
while val<n-1:
    rmv=ll.pop()
    vtx=rmv[1]
    if vtx not in edge:
        continue
    for e in list(edge[vtx]):
        ans_edge[e]=val
        if e in edge[e[0]]:
            edge[e[0]].remove(e)
        if e in edge[e[1]]:
            edge[e[1]].remove(e)
        val+=1
    #del edge[vtx]
for i in el:
    print(ans_edge[i])
        
    