Playing cards(Instack)

why the answer is coming incorrect, i checked the solution with editorial…
import java.util.*;
public class Main
{
public static void main(String[] args)
{
sieve();
Stack s1= new Stack<>();
Stack s2= new Stack<>();
Stack s3= new Stack<>();
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int q=sc.nextInt();
for(int i=0;i<n;i++)
{
s1.push(sc.nextInt());
}
int q=sc.nextInt();
//int d=prime.get(q-1);
Isdivisible(s1,s2,s3,q);
}
static final int max=1299709;
static boolean[] sieve= new boolean[max];
static ArrayList prime= new ArrayList<>();

static void sieve()
{
    for(int i=0;i<max;i++)
    {
        sieve[i]=true;
    }
    sieve[0]=false;
    sieve[1]=false;
    for(int i=2;i<max;i++)
    {
        if(sieve[i]==true)
        {
            prime.add(i);
        for(int j=i*i;j<max && j>=0;j=j+i)
        {
            sieve[j]=false;
        }
        }
    }
    
}

public static void Isdivisible(Stack<Integer> s1,Stack<Integer> s2,Stack<Integer> s3,int q)
{
    for(int i=0;i<q;i++)
    {
    while(!s1.isEmpty())
    {
        int item=s1.pop();
        int d=prime.get(i);
        if(item%d==0)
        {
            s2.push(item);
        }
        else
        {
            s3.push(item);
        }
    }
    }
    
     while(!s2.isEmpty())
    {
        s1.push(s2.pop());
    }
    while(!s3.isEmpty())
    {
        s1.push(s3.pop());
    }
   
    
    Iterator itr= s1.iterator();
    
    while(itr.hasNext())
    {
        System.out.print(itr.next()+" ");
    }
}

}

@minal.251298,
Error:
int q = sc.nextInt(); is written twice. It is written after s1.push for loop as well.
Use static ArrayList< Integer> prime = new ArrayList<>(); Else this will be a Type mismatch Error. Cannot convert from Object to int.

Sample Test Case:
20 21
80 37 86 79 8 39 43 41 15 33 30 15 45 55 61 74 49 49 20 66
Correct Answer:
80
86
8
30
74
20
66
45
15
33
15
39
55
49
49
37
41
43
61
79
Your Answer:
80
86
8
30
74
20
66
37
79
39
43
41
15
33
15
45
55
61
49
49

After correction it is still showing wrong answer

@minal.251298,
The errors that I told you were compilation errors. Your code has logical errors as well as I showed you with the sample test case attached above.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.