You might not want to resieve for primes for each test case.
2
999900000 1000000000
99990000 100000000
With this example, you’ve already sieved for all the primes you need after the first test case, why repeat it for the second? But, even with this change, it’s likely to still be too slow.
You may need a different algorithm. Try searching this forum for some ideas.