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 static java.lang.Math.*;
import java.io.*;

public class E {
	public static void p(Object ...args) {System.out.println(Arrays.deepToString(args));}
	
	public static void main(String[] args) {
		prime = new boolean[1000000];
		Arrays.fill(prime, true);
		prime[0] = false;
		prime[1] = false;
		for (int i = 2; i < prime.length; i++) {
			if (!prime[i])
				continue;
			for (int j = 2; j * i < prime.length; j++)
				prime[j*i] = false;
		}
		
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		DP = new long[2][];
		DP[0] = new long[100000];
		DP[1] = new long[1000];
		for (int zz = 0; zz < T; zz++) {
			Arrays.fill(DP[0], -1);
			Arrays.fill(DP[1], -1);
			String S = in.next();
			int[][] B = new int[5][5];
			N = S.length();
			for (int i = 0; i < N;i++) {
				B[5-N][i+(5-N)] = S.charAt(i)-'0';
				B[i+(5-N)][5-N] = S.charAt(i)-'0';
			}
			
			long ans = solve(N-1, B);
			System.out.println(ans);
		}
	}
	static long[][] DP;
	static int N;
	static boolean[] prime;
	static long solve(int level, int[][] B) {
		if (level == 0)
			return 1;
//		p(level, B);
		
		int h = 0;
		if (level <= 3) {
			h += B[2][1]+B[3][1]*10 + B[4][1]*100;
		}
		if (level <= 2) {
			h += B[3][2]*1000 + B[4][2]*10000;
		}
		if ((level == 2 || level == 3) && DP[level-2][h] != -1)
			return DP[level-2][h];
		long ans = 0;
		
		int start = 0;
		if (level == 4)
			start  = B[1][0]*10000;
		else if(level == 3)
			start = B[2][0]*10000 + B[2][1]*1000;
		else if(level == 2)
			start = B[3][0]*10000 + B[3][1]*1000 + B[3][2]*100;
		else if(level == 1)
			start = B[4][0]*10000 + B[4][1]*1000 + B[4][2]*100 + B[4][3]*10;
		
		int end = 10;
		for (int i = 0; i < level-1; i++)
			end *= 10;
//		System.out.println(start+" "+end);
		for (int i = 0; i < end; i++) {
			int temp = start+i;
			
			if(prime[temp]) {
//				System.out.println(temp);
				for (int j = 0; j < level; j++) {
					B[5-level][4-j] = temp % 10;
					B[4-j][5-level] = temp % 10;
					temp /= 10;
				}
				ans += solve(level-1, B);
			}
		}
		
		if (level == 2 || level == 3) 
			DP[level-2][h] = ans;
//		p(B, level, ans);
		return ans;
	}
}