import numpy as np

import bisect



def prime_number(num):  

  if num == 0 or num == 1:

    return False

  

  if num > 2 and num % 2 == 0:

    return False  

  

  for i in range(3, int(np.sqrt(num)+1)):

    if num % i == 0:

      return False

  

  return True



def check(num):

  if prime_number(num) and prime_number((num+1)//2):

    return True

    

  return False

    

checked = [i for i in range(10**5+1) if check(i)]



# r_list = [sum(checked[:(i+1)]) for i in range(10**5+1)]



# print(checked)



q = int(eval(input()))

for i in range(q):

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

    print((bisect.bisect_right(checked, r) - bisect.bisect_left(checked, l)))
import bisect

a = [True] * 100001

a[0] = False

a[1] = False

p = []

for i in range(2, 100001):

    if a[i]:

        for j in range(i * 2, 100001, i):

            a[j] = False

        if i % 2 != 0 and a[(i + 1) // 2]:

            p.append(i)

q = int(eval(input()))

for i in range(q):

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

    print((bisect.bisect_right(p, r) - bisect.bisect_left(p, l)))
import numpy as np
import bisect


def prime_number(num):
    if num == 0 or num == 1:
        return False
    if num > 2 and num % 2 == 0:
        return False
    for i in range(3, int(np.sqrt(num) + 1)):
        if num % i == 0:
            return False
    return True


def check(num):
    if prime_number(num) and prime_number((num + 1) // 2):
        return True
    return False


checked = [i for i in range(10**5 + 1) if check(i)]
# r_list = [sum(checked[:(i+1)]) for i in range(10**5+1)]
# print(checked)
q = int(eval(input()))
for i in range(q):
    l, r = list(map(int, input().split()))
    print((bisect.bisect_right(checked, r) - bisect.bisect_left(checked, l)))

import bisect

a = [True] * 100001
a[0] = False
a[1] = False
p = []
for i in range(2, 100001):
    if a[i]:
        for j in range(i * 2, 100001, i):
            a[j] = False
        if i % 2 != 0 and a[(i + 1) // 2]:
            p.append(i)
q = int(eval(input()))
for i in range(q):
    l, r = list(map(int, input().split()))
    print((bisect.bisect_right(p, r) - bisect.bisect_left(p, l)))

-import numpy as np - -def prime_number(num): -    if num == 0 or num == 1: -        return False -    if num > 2 and num % 2 == 0: -        return False -    for i in range(3, int(np.sqrt(num) + 1)): -        if num % i == 0: -            return False -    return True - - -def check(num): -    if prime_number(num) and prime_number((num + 1) // 2): -        return True -    return False - - -checked = [i for i in range(10**5 + 1) if check(i)] -# r_list = [sum(checked[:(i+1)]) for i in range(10**5+1)] -# print(checked) +a = [True] * 100001 +a[0] = False +a[1] = False +p = [] +for i in range(2, 100001): +    if a[i]: +        for j in range(i * 2, 100001, i): +            a[j] = False +        if i % 2 != 0 and a[(i + 1) // 2]: +            p.append(i) -    print((bisect.bisect_right(checked, r) - bisect.bisect_left(checked, l))) +    print((bisect.bisect_right(p, r) - bisect.bisect_left(p, l)))