Buggy python submission (verdict: Time Limit Exceeded):
import math
Q_SIZE = math.pow(10,5) 
Q = int(input())

Check_Prime = [-1 for i in range(int(Q_SIZE))]
Count_like = [0 for i in range(int(Q_SIZE//2))]

C_Range_L = 0 
C_Range_R = 0

def check_range(L,R):
    for i in range(L,R+1,2):
        if(Check_Prime[i] < 0):
            if isprime(i):
                Check_Prime[i] = 1
                n = int((i+1)/2)
                if(Check_Prime[n] < 0):
                    if(isprime(n)) : 
                        Count_like[i//2] = 1
                elif(Check_Prime[n] == 1):
                    Count_like[i//2] = 1
            else:
                Check_Prime[i] = 0
                
        elif(Check_Prime[i] == 1):
            n = int((i+1)/2)
            if(Check_Prime[n] < 0):
                if(isprime(n)) : 
                    Count_like[i//2] = 1
            elif(Check_Prime[n] == 1):
                Count_like[i//2] = 1

def isprime(n): 
    if n < 2 : return False 
    if n == 2 : return True 
    if n % 2 == 0 : return False

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

for i in range(Q): 
    l,r = map(int, input().split())

    if(C_Range_L == 0 and C_Range_R == 0):
        check_range(l,r)
        C_Range_L = l
        C_Range_R = r

    if(C_Range_L > l):
        check_range(l,C_Range_L)
        C_Range_L = l

    if(r > C_Range_R):
        check_range(C_Range_R,r)
        C_Range_R = r

    print(sum(Count_like[l//2:r//2+1]))

Fixed submission:
import math
Q_SIZE = int(math.pow(10,5))
Q = int(input())

Check_Prime = [True for i in range(Q_SIZE+1)]
Count_like = [0 for i in range(Q_SIZE//2)]

Check_Prime[0] = False
Check_Prime[1] = False

for i in range(2,Q_SIZE+1):
    if(Check_Prime[i] == True):
        for j in range(i+i,Q_SIZE+1,i):
            Check_Prime[j] = False
            
for i in range(1,Q_SIZE//2):
    if(Check_Prime[i*2+1] == True and Check_Prime[int(((i*2+1)+1)/2)] == True):
        Count_like[i] = Count_like[i-1] + 1
    else:
        Count_like[i] = Count_like[i-1]

for i in range(Q):
    l,r = map(int,input().split())
    if( l == 1):
        print(Count_like[r//2] - Count_like[l//2])
    else:
        print(Count_like[r//2] - Count_like[l//2 - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
Q_SIZE = math.pow(10,5) 
Q = int(input())

Count_Prime = [False for i in range(int(Q_SIZE//2))] 
C_Range_L = 0 
C_Range_R = 0

def check_range(L,R):
    for i in range(L,R+1,2): 
        if(isprime(i) and isprime((i+1)/2)): 
            Count_Prime[i//2] = 1


def isprime(n): 
    if n < 2 : return False 
    if n == 2 : return True 
    if n % 2 == 0 : return False

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

for i in range(Q): 
    l,r = map(int, input().split())

    if(C_Range_L == 0 and C_Range_R == 0):
        check_range(l,r+1)
        C_Range_L = l
        C_Range_R = r

    if(C_Range_L > l):
        check_range(l,C_Range_L+1)
        C_Range_L = l

    if(r > C_Range_R):
        check_range(C_Range_R,r+1)
        C_Range_R = r

    print(sum(Count_Prime[l//2:r//2+1]))

Fixed submission:
import math
Q_SIZE = int(math.pow(10,5))
Q = int(input())

Check_Prime = [True for i in range(Q_SIZE+1)]
Count_like = [0 for i in range(Q_SIZE//2)]

Check_Prime[0] = False
Check_Prime[1] = False

for i in range(2,Q_SIZE+1):
    if(Check_Prime[i] == True):
        for j in range(i+i,Q_SIZE+1,i):
            Check_Prime[j] = False
            
for i in range(1,Q_SIZE//2):
    if(Check_Prime[i*2+1] == True and Check_Prime[int(((i*2+1)+1)/2)] == True):
        Count_like[i] = Count_like[i-1] + 1
    else:
        Count_like[i] = Count_like[i-1]

for i in range(Q):
    l,r = map(int,input().split())
    if( l == 1):
        print(Count_like[r//2] - Count_like[l//2])
    else:
        print(Count_like[r//2] - Count_like[l//2 - 1])

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

Q = int(input())

def isprime(n):
    if n < 2 : return False
    if n == 2 : return True
    if n % 2 == 0 : return False
    
    for i in range(3,int(math.sqrt(n))+1,2):
        if n % i == 0:
            return False
    return True
        

for i in range(Q):
    count_prime = 0
    l,r = map(int, input().split())
    for i in range(l,r+1,2):
        if(isprime(i) and isprime((i+1)/2)):
            count_prime += 1
    print(count_prime)

Fixed submission:
import math
Q_SIZE = int(math.pow(10,5))
Q = int(input())

Check_Prime = [True for i in range(Q_SIZE+1)]
Count_like = [0 for i in range(Q_SIZE//2)]

Check_Prime[0] = False
Check_Prime[1] = False

for i in range(2,Q_SIZE+1):
    if(Check_Prime[i] == True):
        for j in range(i+i,Q_SIZE+1,i):
            Check_Prime[j] = False
            
for i in range(1,Q_SIZE//2):
    if(Check_Prime[i*2+1] == True and Check_Prime[int(((i*2+1)+1)/2)] == True):
        Count_like[i] = Count_like[i-1] + 1
    else:
        Count_like[i] = Count_like[i-1]

for i in range(Q):
    l,r = map(int,input().split())
    if( l == 1):
        print(Count_like[r//2] - Count_like[l//2])
    else:
        print(Count_like[r//2] - Count_like[l//2 - 1])