Prateek loves candy?

I’m getting tle in 1 case pls help

Instead of iterating over p for each test case construct an array of primes such that ith index of that array corresponds to i+1 st prime that way you’d be able to solve each query in O(1)