TLE even after applying SOE

I have attached my code below, I don’t understand why still TLE is coming. The result on submission says Test Case 0 compile message, and then a green tick for other 4 cases. In fact on downloading the input and running on my IDE (Eclipse) gives correct answer. Please help me out!

package challege1;

import java.util.Scanner;

public class sieve {

public static void main(String[] args) {

	Scanner sc = new Scanner(System.in);
	int m = sc.nextInt();
	for (int d = 1; d <= m; d++) {

		int n = sc.nextInt();
		int counter = 1;
		int ans = 1;
		boolean prime[] = new boolean[1000001];

		for (int i = 2; i <= 1000000; i++) {
			prime[i] = true;

		}

		for (int p = 2; p <= 1000; p++) {
			if (prime[p] == true) {

				for (int j = p*p;  j <= 1000000; j=j+p)
					prime[j] = false;

			}

		}
		for (int i = 2; i <= 1000000 && counter <= n; i++) {

			if (prime[i] == true) {
				counter++;
				ans = i;

				// System.out.print(i);
			}

		}

		// TODO Auto-generated method stub

		// System.out.println();
		System.out.println(ans);
	}
}

}