import sys
input=sys.stdin.readline
n=int(input())
d={}
dc={}
for i in range(n-1):
    a,b=map(int,input().split())
    dc[(a,b)]=-1
    if(a not in d):
        d[a]=[]
    if(b not in d):    
        d[b]=[]
    d[a].append(b)
    d[b].append(a)
ct=0
b=False    
for i in d.keys():
    if(len(d[i])>2):
        for j in d[i]:       
            if((i,j) in dc and dc[(i,j)]==-1):
                dc[(i,j)]=ct
                ct+=1
            elif((j,i) in dc and dc[(j,i)]==-1):
                dc[(j,i)]=ct
                ct+=1
            b=True
            if(ct==3):
                break
    if(b==True):
        break
if(b==True):
    val=3
    for i in dc.keys():
        if(dc[i])==-1:
            dc[i]=val
            val+=1
    for i in dc.keys():
        print(dc[i])
else:
    lt=[]
    for i in d.keys():
        if(len(d[i])==1):
            lt.append(i)
    a=lt[0]
    b=lt[1]
    if((a,d[a][0]) in dc):
        dc[(a,d[a][0])]=0
    else:
        dc[(d[a][0],a)]=0
    if((b,d[b][0]) in dc):
        dc[(b,d[b][0])]=1
    else:
        dc[(d[b][0],b)]=1
    val=2
    for i in dc.keys():
        if(dc[i])==-1:
            dc[i]=val
            val+=1
    if(n==2):
        print("0")
    else:
        for i in dc.keys():
            print(dc[i])
        
