pLaying with card(stack)

can u please expain me the question and its approach

hi @divisharoy14_5d0aa86c37c6588a,
A simple approach would be to simply make two arrays of stacks and solve as guided. We can precompute the primes using sieve to save time. This approach will take a lot of space as the sizes of arrays will be size = q+1.
Refer this code