q = int(eval(input()))

a = [list(map(int, input().split())) for i in range(q)]

s = [0]*(2*10**5+2)

s[3] = 1

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

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

        if (i > j and i % j == 0) or (2*i-1) % j == 0:

                b = 0

                break

    else:

        b = 1

    s[2*i-1] = b

S = [0]

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

    c = S[i-1] + s[i]

    S.append(c)

for i in range(q):

    print((S[a[i][1]] - S[a[i][0]-1]))
import math

from itertools import accumulate





def is_prime(n):

    if n == 1:

        return 0



    for k in range(2, int(math.sqrt(n)) + 1):

        if n % k == 0:

            return 0



    return 1





Q = int(eval(input()))

L = [0]*Q

R = [0]*Q



for i in range(Q):

    L[i], R[i] = list(map(int, input().split()))



min_L = min(L)

max_R = max(R)



check = []

for i in range(min_L, max_R+1):

    if (i % 2 == 1):

        flg = (is_prime(i) and is_prime((i+1)/2))

    else:

        flg = 0

    check.append(flg)



# 累積和

check = [0] + check

check = list(accumulate(check))



for i in range(Q):

    print((check[R[i] - min_L + 1] - check[L[i] - min_L]))
q = int(eval(input()))
a = [list(map(int, input().split())) for i in range(q)]
s = [0] * (2 * 10**5 + 2)
s[3] = 1
for i in range(3, 10**5):
    for j in range(2, int((2 * i) ** 0.5) + 2):
        if (i > j and i % j == 0) or (2 * i - 1) % j == 0:
            b = 0
            break
    else:
        b = 1
    s[2 * i - 1] = b
S = [0]
for i in range(1, 10**5 + 1):
    c = S[i - 1] + s[i]
    S.append(c)
for i in range(q):
    print((S[a[i][1]] - S[a[i][0] - 1]))

import math
from itertools import accumulate


def is_prime(n):
    if n == 1:
        return 0
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return 0
    return 1


Q = int(eval(input()))
L = [0] * Q
R = [0] * Q
for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))
min_L = min(L)
max_R = max(R)
check = []
for i in range(min_L, max_R + 1):
    if i % 2 == 1:
        flg = is_prime(i) and is_prime((i + 1) / 2)
    else:
        flg = 0
    check.append(flg)
# 累積和
check = [0] + check
check = list(accumulate(check))
for i in range(Q):
    print((check[R[i] - min_L + 1] - check[L[i] - min_L]))

-q = int(eval(input())) -a = [list(map(int, input().split())) for i in range(q)] -s = [0] * (2 * 10**5 + 2) -s[3] = 1 -for i in range(3, 10**5): -    for j in range(2, int((2 * i) ** 0.5) + 2): -        if (i > j and i % j == 0) or (2 * i - 1) % j == 0: -            b = 0 -            break +import math +from itertools import accumulate + + +def is_prime(n): +    if n == 1: +        return 0 +    for k in range(2, int(math.sqrt(n)) + 1): +        if n % k == 0: +            return 0 +    return 1 + + +Q = int(eval(input())) +L = [0] * Q +R = [0] * Q +for i in range(Q): +    L[i], R[i] = list(map(int, input().split())) +min_L = min(L) +max_R = max(R) +check = [] +for i in range(min_L, max_R + 1): +    if i % 2 == 1: +        flg = is_prime(i) and is_prime((i + 1) / 2) -        b = 1 -    s[2 * i - 1] = b -S = [0] -for i in range(1, 10**5 + 1): -    c = S[i - 1] + s[i] -    S.append(c) -for i in range(q): -    print((S[a[i][1]] - S[a[i][0] - 1])) +        flg = 0 +    check.append(flg) +# 累積和 +check = [0] + check +check = list(accumulate(check)) +for i in range(Q): +    print((check[R[i] - min_L + 1] - check[L[i] - min_L]))