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.*;

//import java.math.*;

public class SolE implements Runnable {
	public static void main(String[] args) {
		new Thread(new SolE()).start();
	}

	@Override
	public void run() {
		try {
//			 br = new BufferedReader(new FileReader("input.txt"));
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
//			time = System.currentTimeMillis();
			solve();
//			System.err.println(System.currentTimeMillis() - time);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

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

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

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

	int MAX = 100000;

	ArrayList<char[]>[][] primes;
	ArrayList<char[]>[][][] primes2;
	ArrayList<char[]>[][][][] primes3;

	int ans;

//	long cnt = 0;
//	long time;

	void out(char[] ch) {
		for (int i = 0; i < ch.length; i++) {
			out.print(ch[i]);
		}
		out.println();
	}
	
	boolean[] np;
	int[] count;

	void bt(int i, char[] ch, char[][] nums, int temp) {
		// cnt++;
		if (i == nums.length - 1) {
//			int t = temp;
//			t *= 10;
//			if (t == 0) {
//				ans++;
//			}
//			for (int j = 1; j < 10; j += 2) {
//				if (!np[t + j]) {
//					ans++;
//				}
//			}
			ans += count[temp];
			return;
		}
		int t = ch[i] - '0';
		ArrayList<char[]> al = null;
		if (i == 1) {
			al = primes[nums.length][t];
		}
		if (i == 2) {
			al = primes2[nums.length][t][nums[1][i] - '0'];
		}
		if (i == 3) {
			al = primes3[nums.length][t][nums[1][i] - '0'][nums[2][i] - '0'];
		}
		for (char[] s : al) {
//			boolean good = true;
//			for (int j = st; j < i; j++) {
//				if (nums[j][i] != s[j]) {
//					good = false;
//					break;
//				}
//			}
//			if (good) {
				nums[i] = s;
				bt(i + 1, ch, nums, 10 * temp + s[nums.length - 1] - '0');
//			}
		}
	}

	void solve() throws IOException {
		primes = new ArrayList[6][10];
		for (int i = 0; i < primes.length; i++) {
			for (int j = 0; j < primes[i].length; j++) {
				primes[i][j] = new ArrayList<char[]>();
			}
		}
		np = new boolean[MAX];
		np[0] = true;
		np[1] = true;
		for (int i = 2; i < MAX; i++) {
			if (!np[i]) {
				int j = 2 * i;
				while (j < np.length) {
					np[j] = true;
					j += i;
				}
				String s = Integer.toString(i);
				primes[s.length()][s.charAt(0) - '0'].add(s.toCharArray());
				for (j = s.length() + 1; j < primes.length; j++) {
					s = "0" + s;
					primes[j][0].add(s.toCharArray());
				}
			}
		}
		primes2 = new ArrayList[6][10][10];
		for (int i = 2; i < primes2.length; i++) {
			for (int j = 0; j < primes2[i].length; j++) {
				for (int k = 0; k < primes2[i][j].length; k++) {
					primes2[i][j][k] = new ArrayList<char[]>();
				}
				for (char[] ch : primes[i][j]) {
					primes2[i][j][ch[1] - '0'].add(ch);
				}
			}
		}
		primes3 = new ArrayList[6][10][10][10];
		for (int i = 3; i < primes2.length; i++) {
			for (int j = 0; j < primes2[i].length; j++) {
				for (int k = 0; k < primes2[i][j].length; k++) {
					for (int l = 0; l < primes3[i][j][k].length; l++) {
						primes3[i][j][k][l] = new ArrayList<char[]>();
					}
					for (char[] ch : primes2[i][j][k]) {
						primes3[i][j][k][ch[2] - '0'].add(ch);
					}
				}
			}
		}
		count = new int[MAX];
		for (int i = 0; i < count.length; i++) {
			for (int j = 0; j < 10; j++) {
				if (10 * i + j < np.length && !np[10 * i + j]) {
					count[i]++;
				}
			}
		}
		// System.err.println(primes[5][0].size());
//		System.err.println(System.currentTimeMillis() - time);
		int t = nextInt();
		HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
		while (t-- > 0) {
			String s = nextToken();
			int p = Integer.parseInt(s);
			if (p == 53) {
				p += 0;
			}
			if (hm.containsKey(p)) {
				out.println(hm.get(p));
				continue;
			}
			int len = s.length();
			ans = 0;
			bt(1, s.toCharArray(), new char[len][], p % 10);
			out.println(ans);
			hm.put(p, ans);
//			System.err.println(cnt);
		}
	}
}