import sys
input=sys.stdin.readline
from collections import defaultdict
n=int(input())
tree=defaultdict(list)
store=[]
for i in range(n-1):
    u,v=map(int,input().split())
    store.append((u,v))
    tree[u].append(v)
    tree[v].append(u)
#print(store,tree)
leave,unleave=0,n-2
for i in range(len(store)):
    if len(tree[store[i][0]])==1:
        print(leave)
        leave+=1
    elif len(tree[store[i][1]])==1:
        print(leave)
        leave+=1
    else:
        print(unleave)
        unleave-=1

        
        

    
    
