from sys import stdin, setrecursionlimit

from itertools import accumulate



setrecursionlimit(10 ** 9)

INF = 1 << 60





def input():

    return stdin.readline().strip()





def prime_numbers(n):

    if n < 2:

        return []



    m = (n + 1) // 2

    p = [True] * m

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

        if p[i]:

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

                p[j] = False



    a = [2 * i + 1 for i in range(m) if p[i]]

    a[0] = 2

    return a





N = 10 ** 5

P = set(prime_numbers(N))

P = [n for n in P if (n + 1) // 2 in P]

a = [0] * (N + 1)

for n in P:

    a[n] = 1

a = list(accumulate(a))



Q = int(eval(input()))

for _ in range(Q):

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

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

from sys import stdin, setrecursionlimit

from itertools import accumulate



setrecursionlimit(10 ** 9)

INF = 1 << 60





def input():

    return stdin.readline().strip()





def prime_numbers(n):

    if n < 2:

        return []



    m = (n + 1) // 2

    p = [True] * m

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

        if p[i]:

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

                p[j] = False



    a = [2 * i + 1 for i in range(m) if p[i]]

    a[0] = 2

    return a





N = 10 ** 5

P = set(prime_numbers(N))

P = [n for n in P if (n + 1) // 2 in P]

a = [0] * (N + 1)

for n in P:

    a[n] = 1

a = list(accumulate(a))



Q, *LR = list(map(int, open(0).read().split()))

for l, r in zip(*[iter(LR)] * 2):

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

from sys import stdin, setrecursionlimit
from itertools import accumulate

setrecursionlimit(10**9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def prime_numbers(n):
    if n < 2:
        return []
    m = (n + 1) // 2
    p = [True] * m
    for i in range(1, int((n**0.5 - 1) / 2) + 1):
        if p[i]:
            for j in range(2 * i * (i + 1), m, 2 * i + 1):
                p[j] = False
    a = [2 * i + 1 for i in range(m) if p[i]]
    a[0] = 2
    return a


N = 10**5
P = set(prime_numbers(N))
P = [n for n in P if (n + 1) // 2 in P]
a = [0] * (N + 1)
for n in P:
    a[n] = 1
a = list(accumulate(a))
Q = int(eval(input()))
for _ in range(Q):
    l, r = list(map(int, input().split()))
    print((a[r] - a[l - 1]))

from sys import stdin, setrecursionlimit
from itertools import accumulate

setrecursionlimit(10**9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def prime_numbers(n):
    if n < 2:
        return []
    m = (n + 1) // 2
    p = [True] * m
    for i in range(1, int((n**0.5 - 1) / 2) + 1):
        if p[i]:
            for j in range(2 * i * (i + 1), m, 2 * i + 1):
                p[j] = False
    a = [2 * i + 1 for i in range(m) if p[i]]
    a[0] = 2
    return a


N = 10**5
P = set(prime_numbers(N))
P = [n for n in P if (n + 1) // 2 in P]
a = [0] * (N + 1)
for n in P:
    a[n] = 1
a = list(accumulate(a))
Q, *LR = list(map(int, open(0).read().split()))
for l, r in zip(*[iter(LR)] * 2):
    print((a[r] - a[l - 1]))

-Q = int(eval(input())) -for _ in range(Q): -    l, r = list(map(int, input().split())) +Q, *LR = list(map(int, open(0).read().split())) +for l, r in zip(*[iter(LR)] * 2):