import sys

import math



def eratosthenes(limit):

    A = [i for i in range(2, limit+1)]

    P = []

    time = 0



    while True:

        prime = min(A)



        if prime > math.sqrt(limit):

            break



        P.append(prime)



        i = 0

        while i < len(A):

            if A[i] % prime == 0:

                A.pop(i)

                continue

            i += 1



    for a in A:

        P.append(a)



    return set(P)



max_n = 10**5



primes = eratosthenes(max_n)

# print(primes)



acum_like_n = [0] * (max_n+1)

for i in range(1, max_n + 1):

    if i in primes and (i+1)//2 in primes:

        acum_like_n[i] = acum_like_n[i-1] + 1

    else:

        acum_like_n[i] = acum_like_n[i-1]

# print(acum_like_n)



Q = int(sys.stdin.readline().strip())

for _ in range(Q):

    l, r = list(map(int, sys.stdin.readline().strip().split()))

    print((acum_like_n[r] - acum_like_n[l-1]))
import sys



input = sys.stdin.readline



Q = int(eval(input()))



primes = set()

not_p = set()

for i in range(2, 10**5 + 1):

# for i in range(2, 10 + 1):

    if i not in not_p:

        primes.add(i)

        for j in range(i+i, 10**5+1, i):

        # for j in range(i+i, 10+1, i):

            not_p.add(j)

# print(primes)

# print(not_p)



acum = [0 for _ in range(10**5+1)]

for i in range(3, 10**5+1, 2):

# for i in range(3, 10, 2):

    if i in primes and ((i+1) // 2) in primes:

        # print(i, "like2017")

        acum[i] += 1

    acum[i] += acum[i-2]

# print(acum[:10])



for _ in range(Q):

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

    print((acum[r] - acum[l - 2]))
import sys
import math


def eratosthenes(limit):
    A = [i for i in range(2, limit + 1)]
    P = []
    time = 0
    while True:
        prime = min(A)
        if prime > math.sqrt(limit):
            break
        P.append(prime)
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
    for a in A:
        P.append(a)
    return set(P)


max_n = 10**5
primes = eratosthenes(max_n)
# print(primes)
acum_like_n = [0] * (max_n + 1)
for i in range(1, max_n + 1):
    if i in primes and (i + 1) // 2 in primes:
        acum_like_n[i] = acum_like_n[i - 1] + 1
    else:
        acum_like_n[i] = acum_like_n[i - 1]
# print(acum_like_n)
Q = int(sys.stdin.readline().strip())
for _ in range(Q):
    l, r = list(map(int, sys.stdin.readline().strip().split()))
    print((acum_like_n[r] - acum_like_n[l - 1]))

import sys

input = sys.stdin.readline
Q = int(eval(input()))
primes = set()
not_p = set()
for i in range(2, 10**5 + 1):
    # for i in range(2, 10 + 1):
    if i not in not_p:
        primes.add(i)
        for j in range(i + i, 10**5 + 1, i):
            # for j in range(i+i, 10+1, i):
            not_p.add(j)
# print(primes)
# print(not_p)
acum = [0 for _ in range(10**5 + 1)]
for i in range(3, 10**5 + 1, 2):
    # for i in range(3, 10, 2):
    if i in primes and ((i + 1) // 2) in primes:
        # print(i, "like2017")
        acum[i] += 1
    acum[i] += acum[i - 2]
# print(acum[:10])
for _ in range(Q):
    l, r = list(map(int, input().split()))
    print((acum[r] - acum[l - 2]))

-import math - -def eratosthenes(limit): -    A = [i for i in range(2, limit + 1)] -    P = [] -    time = 0 -    while True: -        prime = min(A) -        if prime > math.sqrt(limit): -            break -        P.append(prime) -        i = 0 -        while i < len(A): -            if A[i] % prime == 0: -                A.pop(i) -                continue -            i += 1 -    for a in A: -        P.append(a) -    return set(P) - - -max_n = 10**5 -primes = eratosthenes(max_n) +input = sys.stdin.readline +Q = int(eval(input())) +primes = set() +not_p = set() +for i in range(2, 10**5 + 1): +    # for i in range(2, 10 + 1): +    if i not in not_p: +        primes.add(i) +        for j in range(i + i, 10**5 + 1, i): +            # for j in range(i+i, 10+1, i): +            not_p.add(j) -acum_like_n = [0] * (max_n + 1) -for i in range(1, max_n + 1): -    if i in primes and (i + 1) // 2 in primes: -        acum_like_n[i] = acum_like_n[i - 1] + 1 -    else: -        acum_like_n[i] = acum_like_n[i - 1] -# print(acum_like_n) -Q = int(sys.stdin.readline().strip()) +# print(not_p) +acum = [0 for _ in range(10**5 + 1)] +for i in range(3, 10**5 + 1, 2): +    # for i in range(3, 10, 2): +    if i in primes and ((i + 1) // 2) in primes: +        # print(i, "like2017") +        acum[i] += 1 +    acum[i] += acum[i - 2] +# print(acum[:10]) -    l, r = list(map(int, sys.stdin.readline().strip().split())) -    print((acum_like_n[r] - acum_like_n[l - 1])) +    l, r = list(map(int, input().split())) +    print((acum[r] - acum[l - 2]))