n=int(eval(input()))

n+=1

p=[0]*n

a=[0]*n

an=[0]*n

for i in range(1, n):

    p[i],a[p[i]]=list(map(int,input().split()))

mi=n+1

cu=0

for i in range(1,n):

    if mi>a[i]:

        mi=a[i]

    if n-i==mi:

        cn=i-cu

        while cu<i:

            cu+=1

            an[cu]=cn

for i in range(1,n):

    print((an[p[i]]))
n=int(eval(input()))

n+=1

p=[0]*n

a=[0]*n

b=[0]*n

for i in range(1, n):

    p[i],a[p[i]]=list(map(int,input().split()))

m=n+1

c=0

for i in range(1,n):

    m=min(m,a[i])

    if n-i==m:

        d=i-c

        while c<i:

            c+=1

            b[c]=d

for i in range(1,n):

    print((b[p[i]]))
n = int(eval(input()))
n += 1
p = [0] * n
a = [0] * n
an = [0] * n
for i in range(1, n):
    p[i], a[p[i]] = list(map(int, input().split()))
mi = n + 1
cu = 0
for i in range(1, n):
    if mi > a[i]:
        mi = a[i]
    if n - i == mi:
        cn = i - cu
        while cu < i:
            cu += 1
            an[cu] = cn
for i in range(1, n):
    print((an[p[i]]))

n = int(eval(input()))
n += 1
p = [0] * n
a = [0] * n
b = [0] * n
for i in range(1, n):
    p[i], a[p[i]] = list(map(int, input().split()))
m = n + 1
c = 0
for i in range(1, n):
    m = min(m, a[i])
    if n - i == m:
        d = i - c
        while c < i:
            c += 1
            b[c] = d
for i in range(1, n):
    print((b[p[i]]))

-an = [0] * n +b = [0] * n -mi = n + 1 -cu = 0 +m = n + 1 +c = 0 -    if mi > a[i]: -        mi = a[i] -    if n - i == mi: -        cn = i - cu -        while cu < i: -            cu += 1 -            an[cu] = cn +    m = min(m, a[i]) +    if n - i == m: +        d = i - c +        while c < i: +            c += 1 +            b[c] = d -    print((an[p[i]])) +    print((b[p[i]]))