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>
bool p[100000];
int m[] = {1, 3, 7, 9, 2, 5}, x[6];
int solve() {
  int n, t, s = 0;
  scanf("%d", &t);
  for (n = 0; t; t /= 10) x[n++] = t % 10;
  if (n == 2) {
    for (int i = 0; i <= 9; ++i) s += !p[x[0] * 10 + i];
    return s;
  }
  if (n == 3) {
    for (int i = 0; i <= 9; ++i)
      for (int j = 0; j <= 9; ++j)
        if (!p[x[1] * 100 + i * 10 + j])
          for (int k = 0; k <= 9; ++k) s += !(p[x[0] * 100 + j * 10 + k]);
    return s;
  }
  if (n == 4) {
    int A = x[2] ? 3 : 5, B = x[1] ? 3 : 5;
    for (int a = 0; a <= A; ++a)
      for (int b = 0; b <= B; ++b)
        for (int c = 0; c <= 3; ++c)
          if (!p[x[0] * 1000 + m[a] * 100 + m[b] * 10 + m[c]])
            for (int i = 0; i <= 9; ++i)
              for (int j = 0; j <= 9; ++j)
                if (!p[x[2] * 1000 + i * 100 + j * 10 + m[a]])
                  for (int k = 0; k <= 9; ++k)
                    s += !(p[x[1] * 1000 + j * 100 + k * 10 + m[b]]);
    return s;
  }
  int A = x[3] ? 3 : 5, B = x[2] ? 3 : 5, C = x[1] ? 3 : 5;
  for (int a = 0; a <= A; ++a)
    for (int b = 0; b <= B; ++b)
      for (int c = 0; c <= C; ++c)
        for (int d = 0; d <= 3; ++d)
          if (!p[x[0] * 10000 + m[a] * 1000 + m[b] * 100 + m[c] * 10 + m[d]])
            for (int e = 0; e <= 9; ++e)
              for (int f = 0; f <= 9; ++f)
                for (int g = 0; g <= 9; ++g)
                  if (!p[x[3] * 10000 + e * 1000 + f * 100 + g * 10 + m[a]])
                    for (int h = 0; h <= 9; ++h)
                      for (int i = 0; i <= 9; ++i)
                        if (!p[x[2] * 10000 + f * 1000 + h * 100 + i * 10 +
                               m[b]])
                          for (int j = 0; j <= 9; ++j)
                            s += !p[x[1] * 10000 + g * 1000 + i * 100 + j * 10 +
                                    m[c]];
  return s;
}
int main() {
  p[0] = p[1] = 1;
  for (int i = 2; i * i < 100000; ++i)
    if (!p[i])
      for (int j = i * i; j < 100000; j += i) p[j] = 1;
  int T;
  for (scanf("%d", &T); T--;) printf("%d\n", solve());
  return 0;
}