I am unable to pass test cases as time limit exceeds.
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt();
if(testCase <= 10000)
{
int w = 1;
while(w <= testCase)
{
int num = sc.nextInt();
if( num <= 10000)
{
int count = 1;
int i = 2;
int prime = 0;
while(count <= num)
{
int flag = 0;
for(int j = 2; j < i; j++)
{
if(i % j == 0)
{
flag++;
break;
}
}
if(flag == 0)
{
count++;
prime = i;
}
i++;
}
System.out.println(prime);
}
w++;
}
}
}
}