def sort_list(list1, list2): 
  
    zipped_pairs = zip(list2, list1) 
  
    z = [x for _, x in sorted(zipped_pairs)] 
      
    return z 

a=int(input())
x=[0]*(a-1)
y=[0]*(a-1)
c=[0]*(a-1)
d=[0]*(a-1)
for i in range(a-1):
    x[i],y[i]=input().split()
    x[i]=int(x[i])
    y[i]=int(y[i])
    c[i]=y[i]-x[i]
    d[i]=i
for i in range(a-1):
    s=c.index(min(c))
    d[s]=i
    c[s]=max(c)+1
for i in range(a-1):
    print(d[i])

