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

q = int(input())

def is_prime(a):
    if a == 1:
        return False
    for i in range(2,int(math.sqrt(a)+1)):
        if a%i == 0:
            return False
    else:
        return True

s = [0 for i in range(0,100001)]
for i in range(3,100001,2):
    if is_prime(i) and is_prime((i+1)//2):
        s[i] = 1

for i in range(q):
    l,r = map(int,input().split())
    ans = sum(s[l:r+1])
    print(ans)

Fixed submission:
import math

q = int(input())

def is_prime(a):
    if a == 1:
        return False
    for i in range(2,int(math.sqrt(a)+1)):
        if a%i == 0:
            return False
    else:
        return True

s = [0 for i in range(0,100001)]
for i in range(3,100001,2):
    if is_prime(i) and is_prime((i+1)//2):
        s[i] = 1

s2 = [0 for i in range(0,100001)]
tmp = 0
for i in range(100001):
    tmp += s[i]
    s2[i] = tmp

for i in range(q):
    l,r = map(int,input().split())
    ans = s2[r] - s2[l-1]
    print(ans)

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

q = int(input())

def is_prime(a):
    if a == 1:
        return False
    for i in range(2,int(math.sqrt(a)+1)):
        if a%i == 0:
            return False
    else:
        return True

s = [0 for i in range(0,100001)]
for i in range(3,100001,2):
    if is_prime(i) and is_prime((i+1)//2):
        s[i] = 1

for i in range(q):
    l,r = map(int,input().split())
    ans = sum(s[l:r+1])
    print(ans)

Fixed submission:
import math

q = int(input())

def is_prime(a):
    if a == 1:
        return False
    for i in range(2,int(math.sqrt(a)+1)):
        if a%i == 0:
            return False
    else:
        return True

s = [0 for i in range(0,100001)]
for i in range(3,100001,2):
    if is_prime(i) and is_prime((i+1)//2):
        s[i] = 1

s2 = [0 for i in range(0,100001)]
tmp = 0
for i in range(100001):
    tmp += s[i]
    s2[i] = tmp

for i in range(q):
    l,r = map(int,input().split())
    ans = s2[r] - s2[l-1]
    print(ans)

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

q = int(input())

s = [i for i in range(2,100001) if i%2!=0 and i%3!=0 and i%5!=0]
sosu = [2,3,5]
while math.sqrt(100000) <= s[0]:
    sosu.append(s[0])
    for s_num in range(s[0],s[-1]+1,s[0]):
        if s_num in s:
            s.remove(s_num)
sosu = sosu + s
            
for i in range(q):
    l,r = map(int,input().split())
    ans = 0
    for j in range(l,r+1,2):
        if j in sosu and (j+1)//2 in sosu:
            ans += 1
    print(ans)
        


Fixed submission:
import math

q = int(input())

def is_prime(a):
    if a == 1:
        return False
    for i in range(2,int(math.sqrt(a)+1)):
        if a%i == 0:
            return False
    else:
        return True

s = [0 for i in range(0,100001)]
for i in range(3,100001,2):
    if is_prime(i) and is_prime((i+1)//2):
        s[i] = 1

s2 = [0 for i in range(0,100001)]
tmp = 0
for i in range(100001):
    tmp += s[i]
    s2[i] = tmp

for i in range(q):
    l,r = map(int,input().split())
    ans = s2[r] - s2[l-1]
    print(ans)

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

q = int(input())

def sosu(a):
    for i in range(2,math.ceil(math.sqrt(a))+1):
        if a%i == 0:
            dic[a] = 0
            break
    else:
        dic[a] = 1

dic = {1:0,2:1,3:1}
for i in range(q):
    l,r = map(int,input().split())
    ans = 0
    for j in range(l,r+1,2):
        if j not in dic:
            sosu(j)
        if (j+1)//2 not in dic:
            sosu((j+1)//2)
        if dic[j] == 1 and dic[(j+1)//2] == 1:
            ans += 1
    print(ans)
        



Fixed submission:
import math

q = int(input())

def is_prime(a):
    if a == 1:
        return False
    for i in range(2,int(math.sqrt(a)+1)):
        if a%i == 0:
            return False
    else:
        return True

s = [0 for i in range(0,100001)]
for i in range(3,100001,2):
    if is_prime(i) and is_prime((i+1)//2):
        s[i] = 1

s2 = [0 for i in range(0,100001)]
tmp = 0
for i in range(100001):
    tmp += s[i]
    s2[i] = tmp

for i in range(q):
    l,r = map(int,input().split())
    ans = s2[r] - s2[l-1]
    print(ans)