heyy, please check this code.
TLE error in two test cases
@Aparna When the number of test cases is less, your code is working fine.
The problem with your code is that for large number of test cases you are running the prime sieve again and again for each test case which is making the process inefficient and exceeding the time limit. So call the prime sieve function outside the loop for the test case.
Follow this approach:(I have commented out the steps)
Hope this helps 
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.