n = int(input())
ul = [0] * n
vl = [0] * n
data = [0] * (n-1)
for i in range(n-1):
    ul[i], vl[i] = map(int, input().split())
    data[i] = [vl[i]-ul[i], i]
data.sort(key=lambda x: (x[0]))
ansl = [0]*(n-1)
idx = 0
for _, i in data:
    ansl[i] = idx
    idx += 1
for ans in ansl:
    print(ans)
