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.util.*;
import java.io.*;

public class E {
	FastScanner in;
	PrintWriter out;

	int n;
	int[][] a;
	long ans = 0;
	boolean[] prime;
	int[][] cnt;
	int[] num;
	int[] base;

	void gen(int ci, int cj, int cur, int cur2) {
		if (cj == 0) {
			gen(ci - 1, n - 1, cur * cnt[cur2 + base[0] * a[ci][0]][n - 1 - ci], 0);
			return; 
		}
		if (ci == 0) {
			ans += cur;
			return;
		}
		if (a[ci][cj] != -1) {
			gen(ci, cj - 1, cur, cur2  + base[cj] * a[ci][cj]);
			return;
		}

		for (int num = 0; num < 10; num++) {
			a[ci][cj] = a[cj][ci] = num;
			gen(ci, cj - 1, cur, cur2 + base[cj] * num);
		}
		a[ci][cj] = a[cj][ci] = -1;
	}

	public void solve() throws IOException {
		final int MAXP = 99999;
		prime = new boolean[MAXP + 1];
		Arrays.fill(prime, true);
		prime[0] = prime[1] = false;
		cnt = new int[prime.length][6];
		for (int i = 2; i < prime.length; i++) {
			if (prime[i]) {
				for (int j = 2; i * j < prime.length; j++) {
					prime[i * j] = false;
				}
				char[] c = Integer.toString(i).toCharArray();
				for (int j = 0; j < 5; j++) {
					int cur = 0;
					for (int k = 0; k < c.length; k++) {
						int xx = c[k] - '0';
						if (c.length - 1 - k == j)
							xx = 0;
						cur = 10 * cur + xx;
					}
					cnt[cur][j]++;
				}
			}
		}

		int tests = in.nextInt();
		for (int t = 0; t < tests; t++) {
			char[] c = in.next().toCharArray();
			n = c.length;
			num = new int[n];
			a = new int[n][n];
			base = new int[n];
			base[n - 1] = 1;
			for (int i = n - 2; i >= 0; i--)
				base[i] = base[i + 1] * 10;
			for (int[] aa : a)
				Arrays.fill(aa, -1);
			for (int i = 0; i < n; i++)
				a[i][i] = 0;
			for (int i = 0; i < n; i++)
				a[i][0] = a[0][i] = c[i] - '0';
			ans = 0;
			gen(n - 1, n - 1, 1, 0);
			out.println(ans);
		}
	}

	public void run() {
		try {
			in = new FastScanner();
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

	public static void main(String[] arg) {
		new E().run();
	}
}