Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
import bisect
import sys
input = sys.stdin.readline


# 素数判定
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 P

q=int(input())
s= [list(map(int, input().split())) for i in range(q)]
v=eratosthenes(pow(10,5))
ans=[]
for i in range(len(v)):
    x=(v[i]+1)//2
    index = bisect.bisect_left(v, x)
    if v[index]==x:
        ans.append(v[i])

for i,j in s:
    r = bisect.bisect_left(ans, j+1)
    l = bisect.bisect_left(ans, i-1)
    print(r-l)


Fixed submission:
import itertools
from itertools import accumulate

q=int(input())
x=[list(map(int, input().split())) for i in range(q)]
s=[0]*(1+10**5)
#素数のリスト
n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

primes.sort()
for i in range(len(primes)):
    if primes[i]>5*10**4:
        break
    primes.append(2*primes[i])

primes.sort()
count=0
for i in range(len(primes)-1):
    if primes[i+1]-primes[i]==1 and primes[i+1]%2==0:
        s[primes[i]]=1
s=itertools.accumulate(s)
s=list(s)
a=0
b=0
for i in range(q):
    print(s[x[i][1]]-s[x[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
import sys
input = sys.stdin.readline


# 素数判定
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 P

q=int(input())
s= [list(map(int, input().split())) for i in range(q)]
v=eratosthenes(10**5)
w=[0]*(10**5+1)
for i in range(len(v)):
    w[v[i]]+=1

for i in range(10**5,0,-1):
    if w[i]==1:
        if w[(i+1)//2]==1:
            continue
        else:
            w[i]=0
w=list(itertools.accumulate(w))

for i,j in s:
    print(w[j+1] -w[i-1])

Fixed submission:
import itertools
from itertools import accumulate

q=int(input())
x=[list(map(int, input().split())) for i in range(q)]
s=[0]*(1+10**5)
#素数のリスト
n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

primes.sort()
for i in range(len(primes)):
    if primes[i]>5*10**4:
        break
    primes.append(2*primes[i])

primes.sort()
count=0
for i in range(len(primes)-1):
    if primes[i+1]-primes[i]==1 and primes[i+1]%2==0:
        s[primes[i]]=1
s=itertools.accumulate(s)
s=list(s)
a=0
b=0
for i in range(q):
    print(s[x[i][1]]-s[x[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
import sys
input = sys.stdin.readline


# 素数判定
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 P

q=int(input())
s= [list(map(int, input().split())) for i in range(q)]
v=eratosthenes(10**5)
w=[0]*(10**5+1)
for i in range(len(v)):
    w[v[i]]+=1

for i in range(10**5,0,-1):
    if w[i]==1:
        if w[(i+1)//2]==1:
            continue
        else:
            w[i]=0
w=list(itertools.accumulate(w))

for i,j in s:
    print(w[j+1] -w[i-1])

Fixed submission:
import itertools
from itertools import accumulate

q=int(input())
x=[list(map(int, input().split())) for i in range(q)]
s=[0]*(1+10**5)
#素数のリスト
n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

primes.sort()
for i in range(len(primes)):
    if primes[i]>5*10**4:
        break
    primes.append(2*primes[i])

primes.sort()
count=0
for i in range(len(primes)-1):
    if primes[i+1]-primes[i]==1 and primes[i+1]%2==0:
        s[primes[i]]=1
s=itertools.accumulate(s)
s=list(s)
a=0
b=0
for i in range(q):
    print(s[x[i][1]]-s[x[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools


# 素数判定
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 P

q=int(input())
s= [list(map(int, input().split())) for i in range(q)]
v=eratosthenes(10**5)
w=[0]*(10**5+1)
for i in range(len(v)):
    w[v[i]]+=1

for i in range(10**5,0,-1):
    if w[i]==1:
        if w[(i+1)//2]==1:
            continue
        else:
            w[i]=0
w=list(itertools.accumulate(w))


for i,j in s:
    print(w[j+1] -w[i-1])

Fixed submission:
import itertools
from itertools import accumulate

q=int(input())
x=[list(map(int, input().split())) for i in range(q)]
s=[0]*(1+10**5)
#素数のリスト
n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

primes.sort()
for i in range(len(primes)):
    if primes[i]>5*10**4:
        break
    primes.append(2*primes[i])

primes.sort()
count=0
for i in range(len(primes)-1):
    if primes[i+1]-primes[i]==1 and primes[i+1]%2==0:
        s[primes[i]]=1
s=itertools.accumulate(s)
s=list(s)
a=0
b=0
for i in range(q):
    print(s[x[i][1]]-s[x[i][0]-1])