from itertools import accumulate

import sys

input = lambda: sys.stdin.readline().rstrip()



MAX = 10 ** 5



def eratosthenes(n):

    is_prime = [1] * (n+1)

    is_prime[0] = 0

    is_prime[1] = 0



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

        if not is_prime[i]:

            continue

        for j in range(i*2, n+1, i):

            is_prime[j] = 0

    return is_prime        





Q = int(eval(input()))



is_prime = eratosthenes(MAX)



a = [0] * (MAX+1)

for i in range(MAX+1):

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

        a[i] = 1

s = a

s = list(accumulate(s))



for i in range(Q):

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

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

from itertools import accumulate

import sys

input = lambda: sys.stdin.readline().rstrip()





def eratosthenes(n):

    is_prime = [1] * (n + 1)



    is_prime[0] = 0

    is_prime[1] = 0



    ans = [0] * (n+1)



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

        if not is_prime[i]:

            continue

        for j in range(i*2, n+1, i):

            is_prime[j] = 0



    return is_prime





MAX = 10 ** 5





is_prime = eratosthenes(MAX)



a = [0] * (MAX+1)

for i in range(MAX+1):

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

        a[i] = 1



s = list(accumulate(a))





Q = int(eval(input()))



for i in range(Q):

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

    print((s[r]-s[l-1]))
from itertools import accumulate
import sys

input = lambda: sys.stdin.readline().rstrip()
MAX = 10**5


def eratosthenes(n):
    is_prime = [1] * (n + 1)
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = 0
    return is_prime


Q = int(eval(input()))
is_prime = eratosthenes(MAX)
a = [0] * (MAX + 1)
for i in range(MAX + 1):
    if is_prime[i] and is_prime[(i + 1) // 2]:
        a[i] = 1
s = a
s = list(accumulate(s))
for i in range(Q):
    l, r = list(map(int, input().split()))
    print((s[r] - s[l - 1]))

from itertools import accumulate
import sys

input = lambda: sys.stdin.readline().rstrip()


def eratosthenes(n):
    is_prime = [1] * (n + 1)
    is_prime[0] = 0
    is_prime[1] = 0
    ans = [0] * (n + 1)
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = 0
    return is_prime


MAX = 10**5
is_prime = eratosthenes(MAX)
a = [0] * (MAX + 1)
for i in range(MAX + 1):
    if is_prime[i] and is_prime[(i + 1) // 2]:
        a[i] = 1
s = list(accumulate(a))
Q = int(eval(input()))
for i in range(Q):
    l, r = list(map(int, input().split()))
    print((s[r] - s[l - 1]))

-MAX = 10**5 +    ans = [0] * (n + 1) -Q = int(eval(input())) +MAX = 10**5 -s = a -s = list(accumulate(s)) +s = list(accumulate(a)) +Q = int(eval(input()))