import math



Q = int(eval(input()))



# 素数表

n = 100000

P = [False] * n

P[2] = True

for i in range(3, n, 2):

    k = True

    for j in range(3, int(math.sqrt(i)) + 1, 2):

        if i % j == 0:

            k = False

            break

    if k:

        P[i] = True



# Nと(N+1)÷2が素数か否か

a = [0] * n

for i in range(1, n, 2):

    j = (i + 1) // 2

    if P[i] and P[j]:

        a[i] = 1

# 累積和

for i in range(n - 1):

    a[i + 1] += a[i]



for _ in range(Q):

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

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

import sys

from itertools import accumulate



input = sys.stdin.readline



N = int(eval(input()))





def prime_boolean_table(n):

    primes = [True] * (n + 1)

    primes[0] = False

    primes[1] = False

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

        if primes[i]:

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

                primes[j] = False



    return primes





primes = prime_boolean_table(10**5)

A = [0] * 10**5

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

    A[i] += A[i - 1]

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

        A[i] += 1



for _ in range(N):

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

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

import math

Q = int(eval(input()))
# 素数表
n = 100000
P = [False] * n
P[2] = True
for i in range(3, n, 2):
    k = True
    for j in range(3, int(math.sqrt(i)) + 1, 2):
        if i % j == 0:
            k = False
            break
    if k:
        P[i] = True
# Nと(N+1)÷2が素数か否か
a = [0] * n
for i in range(1, n, 2):
    j = (i + 1) // 2
    if P[i] and P[j]:
        a[i] = 1
# 累積和
for i in range(n - 1):
    a[i + 1] += a[i]
for _ in range(Q):
    l, r = list(map(int, input().split()))
    print((a[r] - a[l - 1]))

import sys
from itertools import accumulate

input = sys.stdin.readline
N = int(eval(input()))


def prime_boolean_table(n):
    primes = [True] * (n + 1)
    primes[0] = False
    primes[1] = False
    for i in range(2, n + 1):
        if primes[i]:
            for j in range(i + i, n + 1, i):
                primes[j] = False
    return primes


primes = prime_boolean_table(10**5)
A = [0] * 10**5
for i in range(1, 10**5):
    A[i] += A[i - 1]
    if primes[i] and primes[(i + 1) // 2]:
        A[i] += 1
for _ in range(N):
    l, r = list(map(int, input().split()))
    print((A[r] - A[l - 1]))

-import math +import sys +from itertools import accumulate -Q = int(eval(input())) -# 素数表 -n = 100000 -P = [False] * n -P[2] = True -for i in range(3, n, 2): -    k = True -    for j in range(3, int(math.sqrt(i)) + 1, 2): -        if i % j == 0: -            k = False -            break -    if k: -        P[i] = True -# Nと(N+1)÷2が素数か否か -a = [0] * n -for i in range(1, n, 2): -    j = (i + 1) // 2 -    if P[i] and P[j]: -        a[i] = 1 -# 累積和 -for i in range(n - 1): -    a[i + 1] += a[i] -for _ in range(Q): +input = sys.stdin.readline +N = int(eval(input())) + + +def prime_boolean_table(n): +    primes = [True] * (n + 1) +    primes[0] = False +    primes[1] = False +    for i in range(2, n + 1): +        if primes[i]: +            for j in range(i + i, n + 1, i): +                primes[j] = False +    return primes + + +primes = prime_boolean_table(10**5) +A = [0] * 10**5 +for i in range(1, 10**5): +    A[i] += A[i - 1] +    if primes[i] and primes[(i + 1) // 2]: +        A[i] += 1 +for _ in range(N): -    print((a[r] - a[l - 1])) +    print((A[r] - A[l - 1]))