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 len, test, p, a[6][6], b[11][10010], btot[10], c[110][1010], ctot[100],
    d[1010][110], dtot[1010], etot[10010], s[100010], ans;
void check() {
  for (int i = 2; i <= len; ++i)
    for (int j = 1; j < i; ++j) a[i][j] = a[j][i];
  for (int i = 1; i <= len; ++i) {
    int tmp = 0, t = 1;
    for (int j = len; j >= 1; --j) {
      tmp += a[i][j] * t;
      t *= 10;
    }
    if (s[tmp]) return;
  }
  ++ans;
}
void dfs(int x, int y) {
  if (x > len) {
    check();
    return;
  }
  for (int l = 0; l <= 9; ++l) {
    a[x][y] = l;
    if (y == len)
      dfs(x + 1, x + 1);
    else
      dfs(x, y + 1);
  }
}
int main() {
  s[0] = s[1] = 1;
  for (int i = 2; i < 100000; ++i) {
    if (!s[i]) {
      b[i / 10000][++btot[i / 10000]] = i;
      c[i / 1000][++ctot[i / 1000]] = i;
      d[i / 100][++dtot[i / 100]] = i;
      ++etot[i / 10];
      int t = 100000 / i;
      for (int j = i; j <= t; ++j) s[i * j] = 1;
    }
  }
  scanf("%d", &test);
  for (int i = 1; i <= test; ++i) {
    scanf("%d", &p);
    len = ans = 0;
    while (p) {
      ++len;
      a[1][len] = p % 10;
      p /= 10;
    }
    for (int i = 1; i * 2 <= len; ++i) swap(a[1][i], a[1][len - i + 1]);
    if (len <= 4) {
      dfs(2, 2);
      printf("%d\n", ans);
    } else {
      for (int j = 1; j <= btot[a[1][2]]; ++j) {
        int tmp1 = b[a[1][2]][j], t1 = a[1][3] * 10 + (tmp1 / 100) % 10;
        for (int k = 1; k <= ctot[t1]; ++k) {
          int tmp2 = c[t1][k],
              t2 = a[1][4] * 100 + ((tmp1 / 10) % 10) * 10 + (tmp2 / 10) % 10;
          for (int l = 1; l <= dtot[t2]; ++l) {
            int tmp3 = d[t2][l], t3 = a[1][5] * 1000 + (tmp1 % 10) * 100 +
                                      (tmp2 % 10) * 10 + tmp3 % 10;
            ans += etot[t3];
          }
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}