def prime(x):

  for i in range(2,int(x**0.5)+1):

    if x%i==0:

      return False

  return True



pri = [0]*(100000+1)

for j in range(2,100000+1):

    if prime(j):

        pri[j] = 1



c = [0]*(100000+1)

for i in range(2,100000+1):

    if pri[i]==1 and pri[(i+1)//2]==1:

        c[i] = c[i-1]+1

    else:

        c[i] = c[i-1]



q = int(eval(input()))

for _ in range(q):

    l,r = list(map(int, input().split()))

    print((c[r]-c[l-1]))
def prime(x):

  for i in range(2,int(x**0.5)+1):

    if x%i==0:

      return False

  return True

c = [0]*100002

for k in range(2,100001):

    if prime(k):

        c[k]=1





pri = [0]*100002

for i in range(2,100001):

    if c[i]==1 and c[(i+1)//2]==1:

        pri[i] = pri[i-1] +1 

    else:

        pri[i] = pri[i-1]



q = int(eval(input()))

a = [list(map(int, input().split())) for _ in range(q)]

for l,r in a:

    print((pri[r]-pri[l-1]))

def prime(x):
    for i in range(2, int(x**0.5) + 1):
        if x % i == 0:
            return False
    return True


pri = [0] * (100000 + 1)
for j in range(2, 100000 + 1):
    if prime(j):
        pri[j] = 1
c = [0] * (100000 + 1)
for i in range(2, 100000 + 1):
    if pri[i] == 1 and pri[(i + 1) // 2] == 1:
        c[i] = c[i - 1] + 1
    else:
        c[i] = c[i - 1]
q = int(eval(input()))
for _ in range(q):
    l, r = list(map(int, input().split()))
    print((c[r] - c[l - 1]))

def prime(x):
    for i in range(2, int(x**0.5) + 1):
        if x % i == 0:
            return False
    return True


c = [0] * 100002
for k in range(2, 100001):
    if prime(k):
        c[k] = 1
pri = [0] * 100002
for i in range(2, 100001):
    if c[i] == 1 and c[(i + 1) // 2] == 1:
        pri[i] = pri[i - 1] + 1
    else:
        pri[i] = pri[i - 1]
q = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(q)]
for l, r in a:
    print((pri[r] - pri[l - 1]))

-pri = [0] * (100000 + 1) -for j in range(2, 100000 + 1): -    if prime(j): -        pri[j] = 1 -c = [0] * (100000 + 1) -for i in range(2, 100000 + 1): -    if pri[i] == 1 and pri[(i + 1) // 2] == 1: -        c[i] = c[i - 1] + 1 +c = [0] * 100002 +for k in range(2, 100001): +    if prime(k): +        c[k] = 1 +pri = [0] * 100002 +for i in range(2, 100001): +    if c[i] == 1 and c[(i + 1) // 2] == 1: +        pri[i] = pri[i - 1] + 1 -        c[i] = c[i - 1] +        pri[i] = pri[i - 1] -for _ in range(q): -    l, r = list(map(int, input().split())) -    print((c[r] - c[l - 1])) +a = [list(map(int, input().split())) for _ in range(q)] +for l, r in a: +    print((pri[r] - pri[l - 1]))