Problem: Polycarpus has t safes. The password for each safe is a square matrix consisting of decimal digits '0' ... '9' (the sizes of passwords to the safes may vary). Alas, Polycarpus has forgotten all passwords, so now he has to restore them.

Polycarpus enjoys prime numbers, so when he chose the matrix passwords, he wrote a prime number in each row of each matrix. To his surprise, he found that all the matrices turned out to be symmetrical (that is, they remain the same after transposition). Now, years later, Polycarp was irritated to find out that he remembers only the prime numbers pi, written in the first lines of the password matrices.

For each safe find the number of matrices which can be passwords to it.

The number of digits in pi determines the number of rows and columns of the i-th matrix. One prime number can occur in several rows of the password matrix or in several matrices. The prime numbers that are written not in the first row of the matrix may have leading zeros.

Input

The first line of the input contains an integer t (1 ≤ t ≤ 30) — the number of safes. Next t lines contain integers pi (10 ≤ pi ≤ 99999), pi is a prime number written in the first row of the password matrix for the i-th safe. All pi's are written without leading zeros.

Output

Print t numbers, the i-th of them should be the number of matrices that can be a password to the i-th safe. Print the numbers on separate lines.

Examples

Input

4
11
239
401
9001


Output

4
28
61
2834

Note

Here is a possible password matrix for the second safe: 
    
    
      
    239  
    307  
    977  
    

Here is a possible password matrix for the fourth safe: 
    
    
      
    9001  
    0002  
    0002  
    1223   
    

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;


public class Main implements Runnable {

	public void _main() throws IOException {
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for (int i = 2; i < N; i++) {
			if (isPrime[i]) {
				for (int j = i + i; j < N; j += i) {
					isPrime[j] = false;
				}
			}
		}
		p10[0] = 1;
		for (int i = 1; i < p10.length; i++) {
			p10[i] = 10 * p10[i - 1];
		}
		
		int nTests = nextInt();
		for (int test = 1; test <= nTests; test++) {
			String firstRow = next();
			int n = firstRow.length();
			m = new int[n][n];
			res = 0;
			for (int i = 0; i < n; i++) {
				int c = firstRow.charAt(i) - '0';
				m[0][i] = c;
				m[i][0] = c;
			}
			rec(1, 2, n, 1);
			out.println(res);
		}
	}

	private void rec(int r, int c, int n, int prod) {
		if (r == n) {
			res += prod;
			return;
		}
		if (c == n) {
			int x = 0;
			int i = r;
			for (int j = 0; j < n; j++) {
				x = 10 * x + m[i][j];
			}
			int cur = 0;
			for (int j = 0; j < 10; j++) {
				int y = x + p10[n - i - 1] * (j - digit(x, n - i - 1));
				if (isPrime[y])
					++cur;
			}
			if (cur != 0)
				rec(r + 1, r + 2, n, prod * cur);
			return;
		}
		for (int i = 0; i < 10; i++) {
			m[r][c] = i;
			m[c][r] = i;
			rec(r, c + 1, n, prod);
		}
	}

	final int N = 100000;
	boolean[] isPrime = new boolean[N];
	int res = 0;
	int[][] m;
	int[] p10 = new int[10];
	
	int digit(int x, int i) {
		return (x / p10[i]) % 10;
	}


	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	private String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String rl = in.readLine();
			if (rl == null)
				return null;
			st = new StringTokenizer(rl);
		}
		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.UK);
		new Thread(new Main()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			//in = new BufferedReader(new FileReader("a.in"));
			//out = new PrintWriter(new FileWriter("a.out"));

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}