import sys
import math
input=sys.stdin.readline
#t=int(input())
t=1
for _ in range(t):
    n=int(input())
    #x,y=map(int,input().split())
    #a=list(map(int,input().split()))
    d={}
    fr=[]
    to=[]
    for i in range(1,n+1):
        d[i]=[]
    for i in range(n-1):
        u,v=map(int,input().split())
        d[u].append(v)
        d[v].append(u)
        fr.append(u)
        to.append(v)
    weight={}
    k=0
    for i in range(1,n+1):
        if len(d[i])==1:
            weight[i]=k
            k+=1
    if n==2:
        weight[1]=0
        weight[2]=0
    for i in range(n-1):
        if weight.get(fr[i],-1)!=-1 :
            print(weight[fr[i]])
        elif  weight.get(to[i],-1)!=-1 :
            print(weight[to[i]])
        else:
            print(k)
            k+=1
        
            
            
        