Unable to understand ith iteration in Playing Cards probem

So basically we have to move the element from B which are not prime and prime elements into A. Then move the elements from to B. I am not understanding for add iterations in code. Can you please explain briefly

There are Q iterations , in ith iteration you start picking the cards from A(i-1)th pile .
eg:- you are given N=5 , Q=1 and card :- 3 4 7 6 5 where 3 is representing top element of stack.
Now your 1st iteration starts i.e i=1 :- You will now start picking the card from A(i-1)th pile i.e A0 th pile
therefore you pop first element of A0 which is 3, Now if 3 is divisible by ith prime here i=1 i.e 1st prime no and we know first prime no is 2 , Since 3 is not divisible by 2 we put 3 into new pile i.e A1th pile .
Now the top element becomes 4 so 4 is divisible by 2 therefore we add 4 to the new pile B1th . In similar way we move ahead.