def prime(n):

    is_prime=[True]*(n+1)

    is_prime[0],is_prime[1]=False,False

    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]=False

    return [i for i in range(n+1) if is_prime[i]]



prime_number=prime(10**5)

number=[i for i in prime_number if (i+1)//2 in prime_number]+[0]

ans=[0]*(10**5+1)

count=0



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

    ans[i]=ans[i-1]

    if i==number[count]:

        ans[i] +=1

        count +=1



for i in range(int(eval(input()))):

    a,b=list(map(int,input().split()))

    print((ans[b]-ans[a-1]))
def prime(n):

    is_prime=[True]*(n+1)

    is_prime[0],is_prime[1]=False,False

    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]=False

    return [i for i in range(n+1) if is_prime[i]]





q=int(eval(input()))

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

prime=prime(10**5)



DP=[0]*(10**5+1)

for i in prime:

    if i*2-1 in prime:

        DP[i*2-1]=1



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

    DP[i]=DP[i-1]+DP[i]



for l,r in LR:

    print((DP[r]-DP[l-1]))
def prime(n):
    is_prime = [True] * (n + 1)
    is_prime[0], is_prime[1] = False, False
    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] = False
    return [i for i in range(n + 1) if is_prime[i]]


prime_number = prime(10**5)
number = [i for i in prime_number if (i + 1) // 2 in prime_number] + [0]
ans = [0] * (10**5 + 1)
count = 0
for i in range(1, 10**5):
    ans[i] = ans[i - 1]
    if i == number[count]:
        ans[i] += 1
        count += 1
for i in range(int(eval(input()))):
    a, b = list(map(int, input().split()))
    print((ans[b] - ans[a - 1]))

def prime(n):
    is_prime = [True] * (n + 1)
    is_prime[0], is_prime[1] = False, False
    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] = False
    return [i for i in range(n + 1) if is_prime[i]]


q = int(eval(input()))
LR = [list(map(int, input().split())) for _ in range(q)]
prime = prime(10**5)
DP = [0] * (10**5 + 1)
for i in prime:
    if i * 2 - 1 in prime:
        DP[i * 2 - 1] = 1
for i in range(1, 10**5 + 1):
    DP[i] = DP[i - 1] + DP[i]
for l, r in LR:
    print((DP[r] - DP[l - 1]))

-prime_number = prime(10**5) -number = [i for i in prime_number if (i + 1) // 2 in prime_number] + [0] -ans = [0] * (10**5 + 1) -count = 0 -for i in range(1, 10**5): -    ans[i] = ans[i - 1] -    if i == number[count]: -        ans[i] += 1 -        count += 1 -for i in range(int(eval(input()))): -    a, b = list(map(int, input().split())) -    print((ans[b] - ans[a - 1])) +q = int(eval(input())) +LR = [list(map(int, input().split())) for _ in range(q)] +prime = prime(10**5) +DP = [0] * (10**5 + 1) +for i in prime: +    if i * 2 - 1 in prime: +        DP[i * 2 - 1] = 1 +for i in range(1, 10**5 + 1): +    DP[i] = DP[i - 1] + DP[i] +for l, r in LR: +    print((DP[r] - DP[l - 1]))