import numpy as np

import itertools

Q = int(eval(input()))

LR = [[int(x) for x in input().split()] for _ in range(Q)]





## エラトステネスの篩

MAX = 10**5

is_prime = np.full(MAX, True)

is_prime[0] = is_prime[1] = False

for i in range(2, int(MAX**.5)+1):

    if is_prime[i]:

        is_prime[i*i::i] = False

        

NUM = np.zeros(MAX)

for p in range(MAX):

    if is_prime[p] and is_prime[(p+1)//2]:

        NUM[p] += 1



NUMcum = [0] + list(itertools.accumulate(NUM))



for l, r in LR:

    print((int(NUMcum[r+1] - NUMcum[l])))
import itertools

Q = int(eval(input()))

LR = [[int(x) for x in input().split()] for _ in range(Q)]



MAX = 10**5

is_prime = [True] * MAX

is_prime[0] = is_prime[1] = False

for i in range(2, int(MAX**.5)+1):

    if is_prime[i]:

        for j in range(i*i, MAX, i):

            is_prime[j] = False



NUM = [0] * MAX

for p in range(MAX):

    if is_prime[p] and is_prime[(p+1)//2]:

        NUM[p] += 1

NUMcum = [0] + list(itertools.accumulate(NUM))

for l, r in LR:

    print((int(NUMcum[r+1] - NUMcum[l])))
import numpy as np
import itertools

Q = int(eval(input()))
LR = [[int(x) for x in input().split()] for _ in range(Q)]
## エラトステネスの篩
MAX = 10**5
is_prime = np.full(MAX, True)
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX**0.5) + 1):
    if is_prime[i]:
        is_prime[i * i :: i] = False
NUM = np.zeros(MAX)
for p in range(MAX):
    if is_prime[p] and is_prime[(p + 1) // 2]:
        NUM[p] += 1
NUMcum = [0] + list(itertools.accumulate(NUM))
for l, r in LR:
    print((int(NUMcum[r + 1] - NUMcum[l])))

import itertools

Q = int(eval(input()))
LR = [[int(x) for x in input().split()] for _ in range(Q)]
MAX = 10**5
is_prime = [True] * MAX
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX**0.5) + 1):
    if is_prime[i]:
        for j in range(i * i, MAX, i):
            is_prime[j] = False
NUM = [0] * MAX
for p in range(MAX):
    if is_prime[p] and is_prime[(p + 1) // 2]:
        NUM[p] += 1
NUMcum = [0] + list(itertools.accumulate(NUM))
for l, r in LR:
    print((int(NUMcum[r + 1] - NUMcum[l])))

-import numpy as np -## エラトステネスの篩 -is_prime = np.full(MAX, True) +is_prime = [True] * MAX -        is_prime[i * i :: i] = False -NUM = np.zeros(MAX) +        for j in range(i * i, MAX, i): +            is_prime[j] = False +NUM = [0] * MAX