// Arup Guha
// Solution to Junior Knights Problem: Next Prime
// 10/31/2015

import java.util.*;

public class nextprime {

	// Just a guess - this just has to be big enough to include the next prime beyond 1000000.
	final public static int LIMIT =   1001000;
	final public static int MAXCASE = 1000000;

	public static void main(String[] args) {

		// Run prime sieve.
		boolean[] sieve = new boolean[LIMIT];
		Arrays.fill(sieve, true);
		sieve[0] = sieve[1] = false;
		for (int i=2; i<LIMIT; i++)
			for (int j=2*i; j<LIMIT; j+=i)
				sieve[j] = false;

		// Pre-calculate all results in order. Any time we hit a value that is prime
		// for our array index, we just search in order in our prime sieve array for
		// the next prime.
		int[] results = new int[MAXCASE+1];
		int nextP = 2;
		for (int i=0; i<results.length; i++) {
			if (nextP == i) {
				nextP++;
				while (!sieve[nextP]) nextP++;
			}
			results[i] = nextP;
		}

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process all cases.
		for (int loop=0; loop<numCases; loop++)
			System.out.println(results[stdin.nextInt()]);
	}
}
