Can you please explain the question using the input format?

You are at a casino. There are N stacked cards on pile . Each card has a number written on it. Then there will be Q iterations. In ith iteration, you start picking up the cards in Ai-1th pile from the top one by one and check whether the number written on the card is divisible by the ith prime number. If the number is divisible, you stack that card on pile Bi. Otherwise, you stack that card on pile Ai. After Q iterations, cards can only be on pile B1, B2, B3, . . . BQ, AQ . Output numbers on these cards from top to bottom of each piles in order of B1, B2, B3, . . . BQ, AQ .

Input Format
First line contains N and Q. The next line contains N space separated integers representing the initial pile of cards i.e., A0. The leftmost value represents the bottom plate of the pile.

Constraints
N < 10^5
Q < 10^5
|Ai| < 10^9

Output Format
Output N lines, each line containing the number written on the card.

Sample Input
5 1
3 4 7 6 5

hi @Mukul-Shane-1247687648773500,
N is the no. of cards in A(0)th stack.
Q is the no. of iterations you have to perform.
The third input is N numbers, representing the number of cards present in A(0)th stack.

Consider the following input:
INPUT:
N=5
Q=2
A(0)th stack : 1 2 3 4 5

Processing:
iterate for i =1 to Q;

for i=1(frst iteration):

Pop top element of A(i-1)th (A(0)th) stack i.e. 5
Check, ((top_element i.e. 5)%(ith prime number i.e. 1st prime number, 2)) == 0 ? Push top_element to B(i) i.e. B(1)th stack : Push top_element to A(i)i.e.A(1)th stack;
After repeating the same for all elements of stack A(0):
A(0)=[] i.e. empty as all elements have been popped.
A(1)=[5,3,1] as they are not divisible by 2.
B(1)=[4,2] as they are divisible by 2.

for i=2=Q (second and last iteration):

Pop top element of A(i-1)th (A(1)th) stack i.e. 1
Check, ((top_element i.e. 1)%(ith prime number i.e. 2nd prime number, 3)) == 0 ? Push top_element to B(i) i.e. B(2)th stack : Push top_element to A(i)i.e.A(2)th stack;
After repeating the same for all elements of stack A(1):
A(1)=[] i.e. empty as all elements have been popped.
A(2)=[1,5] as they are not divisible by 3.
B(2)=[3] as they are divisible by 3.

Output:
print elements of B(1),B(2),A(2)

2
4
3
5
1

Note: top element of the stack is popped first.

@Mukul-Shane-1247687648773500,
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