n = int(input())                    
if n == 2:                          
    print(0)                        
    raise SystemExit                
                                    
arr = [None for _ in range(n)]      
                                    
for i in range(n-1):                
    a, b = map(int, input().split())
    a -= 1                          
    b -= 1                          
                                    
    if arr[a] == None:              
        arr[a] = i                  
    else:                           
        arr[a] = False              
                                    
    if arr[b] == None:              
        arr[b] = i                  
    else:                           
        arr[b] = False              
                                    
ret = [-1 for _ in range(n-1)]      
i = 0                               
for e in arr:                       
    if type(e) == int:              
        ret[e] = i                  
        i += 1                      
                                    
for j in range(n-1):                
    if ret[j] == -1:                
        ret[j] = i                  
        i += 1                      
                                    
print("\n".join(map(str, ret)))     