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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int esprimo[1000000];
long long int memmaneras[5][1000000];
int calculado[5][1000000];
long long int maneras(int nivel, int contexto) {
  long long int &mem = memmaneras[nivel][contexto];
  if (calculado[nivel][contexto]) return mem;
  calculado[nivel][contexto] = 1;
  if (nivel == 1) {
    int c = contexto * 10;
    for (int d = 0; d <= 9; d++) mem += esprimo[c + d];
  } else if (nivel == 2) {
    int c1 = contexto / 1000 * 100;
    int c2 = contexto % 1000 * 10;
    for (int x = 0; x < 100; x++)
      if (esprimo[c1 + x]) mem += maneras(1, c2 + x % 10);
  } else if (nivel == 3) {
    int c1 = contexto / 10000 * 1000;
    int c2 = contexto / 100 % 100 * 10000;
    int c3 = contexto % 100 * 10;
    for (int x = 0; x < 1000; x++)
      if (esprimo[c1 + x])
        mem += maneras(2, c2 + x / 10 % 10 * 1000 + c3 + x % 10);
  } else {
    int c1 = contexto / 1000 * 10000;
    int c2 = contexto / 100 % 10 * 100000;
    int c3 = contexto / 10 % 10 * 1000;
    int c4 = contexto % 10 * 10;
    for (int x = 0; x < 10000; x++)
      if (esprimo[c1 + x])
        mem += maneras(3, c2 + x / 100 % 10 * 10000 + c3 + x / 10 % 10 * 100 +
                              c4 + x % 10);
  }
  return mem;
}
int numdigitos(int x) {
  int num = 0;
  while (x > 0) {
    num++;
    x /= 10;
  }
  return num;
}
int main() {
  for (int i = 2; i < 1000000; i++) esprimo[i] = 1;
  for (int i = 2; i < 1000000; i++)
    if (esprimo[i])
      for (int j = i + i; j < 1000000; j += i) esprimo[j] = 0;
  int casos;
  cin >> casos;
  for (int cas = 0; cas < casos; cas++) {
    int contexto;
    cin >> contexto;
    int nd = numdigitos(contexto);
    if (nd == 5) {
      contexto = contexto % 10000;
    } else if (nd == 4) {
      contexto = contexto / 100 % 10 * 10000 + contexto / 10 % 10 * 100 +
                 contexto % 10;
    } else if (nd == 3) {
      contexto = contexto / 10 % 10 * 1000 + contexto % 10;
    } else if (nd == 2) {
      contexto = contexto % 10;
    }
    cout << maneras(nd - 1, contexto) << endl;
  }
}