
n = input()
c=0
right=[]
left = []
l=[]
for __ in range(n-1):
    a,b = map(int,raw_input().split())
    l.append([a,b])
    if c!=a:
        left.append([a,b])
        c=a
    else:
        right.append([a,b])
right = right[::-1]
print 0
#print left,right
for i in range(1,n-1):
    if l[i] in right:
        print right.index(l[i])+1
    else:
        print left.index(l[i]) + len(right) + 1
    



        
        
