Buggy python submission (verdict: Time Limit Exceeded):
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


arr = get_sieve_of_eratosthenes(100000)

arr_2 = []

for i in range(1, len(arr)):
    if (arr[i] + 1) / 2 in arr:
        arr_2.append(arr[i])

Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    left_ind = bisect.bisect_left(arr_2, l)
    right_ind = bisect.bisect_right(arr_2, r)
    print(right_ind - left_ind)

Fixed submission:
import bisect
import math

def prime(n):
    for j in range(2, int(math.sqrt(n) + 1)):
        if n % j == 0:
            return False
    return True

lis = []
for i in range(3, 100000, 2):
    if prime(i) and prime((i + 1) / 2):
        lis.append(i)

Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    left_ind = bisect.bisect_left(lis, l)
    right_ind = bisect.bisect_right(lis, r)
    print(right_ind - left_ind)

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


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    needed_prime = []
    data = [i + 1 for i in range(1, n)]
    i = 0
    for i in range(9592):
        p = data[0]
        prime.append(p)
        if int((p + 1) / 2) in prime and p != 2:
            needed_prime.append(p)
            #print(needed_prime)
        data = [e for e in data if (e % p != 0)]
    return needed_prime


arr = get_sieve_of_eratosthenes(100000)

Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    left_ind = bisect.bisect_left(arr, l)
    right_ind = bisect.bisect_right(arr, r)
    print(right_ind - left_ind)

Fixed submission:
import bisect
import math

def prime(n):
    for j in range(2, int(math.sqrt(n) + 1)):
        if n % j == 0:
            return False
    return True

lis = []
for i in range(3, 100000, 2):
    if prime(i) and prime((i + 1) / 2):
        lis.append(i)

Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    left_ind = bisect.bisect_left(lis, l)
    right_ind = bisect.bisect_right(lis, r)
    print(right_ind - left_ind)

Buggy python submission (verdict: Runtime Error):
import math
import bisect


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    needed_prime = [2]
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return needed_prime + data
        prime.append(p)
        if int((p + 1) / 2) in prime and p != 2:
            needed_prime.append(p)
        data = [e for e in data if (e % p != 0)]


arr = get_sieve_of_eratosthenes(100000)


Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    left_ind = bisect.bisect_left(arr_2, l)
    right_ind = bisect.bisect_right(arr_2, r)
    print(right_ind - left_ind)

Fixed submission:
import bisect
import math

def prime(n):
    for j in range(2, int(math.sqrt(n) + 1)):
        if n % j == 0:
            return False
    return True

lis = []
for i in range(3, 100000, 2):
    if prime(i) and prime((i + 1) / 2):
        lis.append(i)

Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    left_ind = bisect.bisect_left(lis, l)
    right_ind = bisect.bisect_right(lis, r)
    print(right_ind - left_ind)

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


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if (e % p != 0)]


arr = get_sieve_of_eratosthenes(100000)

arr_2 = [e for e in arr if int((e + 1) / 2) in arr]


Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    left_ind = bisect.bisect_left(arr_2, l)
    right_ind = bisect.bisect_right(arr_2, r)
    print(right_ind - left_ind)

Fixed submission:
import bisect
import math

def prime(n):
    for j in range(2, int(math.sqrt(n) + 1)):
        if n % j == 0:
            return False
    return True

lis = []
for i in range(3, 100000, 2):
    if prime(i) and prime((i + 1) / 2):
        lis.append(i)

Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    left_ind = bisect.bisect_left(lis, l)
    right_ind = bisect.bisect_right(lis, r)
    print(right_ind - left_ind)