n = int(input())
adj = []
deg = [0 for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    adj += [[a-1,b-1]]
    deg[a-1] += 1
    deg[b-1] += 1
op = []
cnt = 0
cnt1 = n-2
for i in adj:
    if(deg[i[0]] == 1 or deg[i[1]]==1):
        op += [cnt]
        cnt += 1
    else:
        op += [cnt1]
        cnt1 -= 1
for i in op:
    print(i)
        
    

    
