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 static java.util.Arrays.deepToString;

import java.io.*;
import java.math.*;
import java.util.*;

public class E {
	final static int MX = 100000;
	static int[] primes;
	static String[] ps;
	static ArrayList<Integer>[][][] lst;
	static int[][][][] arr_lst;

	static void precalc() {
		boolean[] isPrime = new boolean[MX];
		Arrays.fill(isPrime, true);
		for (int i = 2; i * i < MX; i++) {
			if (isPrime[i]) {
				for (int j = i * i; j < MX; j += i) {
					isPrime[j] = false;
				}
			}
		}
		primes = new int[MX];
		int cnt = 0;
		for (int i = 2; i < MX; i++) {
			if (isPrime[i]) {
				primes[cnt++] = i;
			}
		}
		primes = Arrays.copyOf(primes, cnt);
		ps = new String[primes.length];
		for (int i = 0; i < primes.length; i++) {
			ps[i] = primes[i] + "";
		}
		lst = new ArrayList[6][5][10000];
		for (int i = 0; i < primes.length; i++) {
			int L = ps[i].length();
			for (int curL = L; curL < 6; curL++) {
				int tmp = 0;
				for (cnt = 1; cnt < curL; cnt++) {
					int index = cnt - 1 - (curL - L);
					tmp = tmp * 10 + (index >= 0 ? ps[i].charAt(index) - '0' : 0);
					if (lst[curL][cnt][tmp] == null) {
						lst[curL][cnt][tmp] = new ArrayList<>(0);
					}
					lst[curL][cnt][tmp].add(primes[i]);
				}
			}
		}
		arr_lst = new int[6][5][10000][0];
		for (int i = 0; i < lst.length; i++) {
			for (int j = 0; j < lst[0].length; j++) {
				for (int t = 0; t < lst[0][0].length; t++) {
					ArrayList<Integer> list = lst[i][j][t];
					if (list == null) {
						continue;
					}
					arr_lst[i][j][t] = new int[list.size()];
					for (int q = 0; q < list.size(); q++) {
						arr_lst[i][j][t][q] = list.get(q);
					}
				}
			}
		}
	}

	static int[][] stack;

	static int go(int[] arr, int row, int n) {
		for (int i = row; i < n; i++) {
			if (arr_lst[n][row][arr[i]].length == 0)
				return 0;
		}
		int ret = 0;
		for (int prime : arr_lst[n][row][arr[row]]) {
			if (row + 1 == n) {
				ret++;
				continue;
			}
			int[] narr = stack[row + 1];
			for (int i = 0; i < row; i++) {
				narr[i] = arr[i];
			}
			narr[row] = prime;
			for (int i = n - 1; i > row; i--) {
				narr[i] = arr[i] * 10 + (prime % 10);
				prime /= 10;
			}
			ret += go(narr, row + 1, n);
		}
		return ret;
	}

	static int solve(int P) {
		String Ps = P + "";
		int k = Ps.length();
		int[] arr = new int[k];
		arr[0] = P;
		for (int i = 1; i < k; i++) {
			arr[i] = Ps.charAt(i) - '0';
		}
		stack = new int[k][k];
		return go(arr, 1, k);
	}

	public static void main(String[] args) throws Exception {
		reader = new BufferedReader(new InputStreamReader(System.in));
		writer = new PrintWriter(System.out);

		setTime();
		precalc();
		printTime();
		
//		long maxT = 0;
//		for (int p : primes) {
//			// debug(p);
//			setTime();
//			solve(p);
//			long T = System.currentTimeMillis() - systemTime;
//			if (T > maxT) {
//				maxT = T;
//				debug(T, p);
//			}
//		}

		setTime();
		int T = nextInt();
		for (int i = 0; i < T; i++) {
			int P = nextInt();
			int ans = solve(P);
			writer.println(ans);
		}
		printTime();
		printMemory();

		writer.close();
	}

	static BufferedReader reader;
	static PrintWriter writer;
	static StringTokenizer tok = new StringTokenizer("");
	static long systemTime;

	static void debug(Object... o) {
		System.err.println(deepToString(o));
	}

	static void setTime() {
		systemTime = System.currentTimeMillis();
	}

	static void printTime() {
		System.err.println("Time consumed: " + (System.currentTimeMillis() - systemTime));
	}

	static void printMemory() {
		System.err.println("Memory consumed: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + "kb");
	}

	static String next() {
		while (!tok.hasMoreTokens()) {
			String w = null;
			try {
				w = reader.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (w == null)
				return null;
			tok = new StringTokenizer(w);
		}
		return tok.nextToken();
	}

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

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

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

	static BigInteger nextBigInteger() {
		return new BigInteger(next());
	}
}