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 p10[] = {1, 10, 100, 1000, 10000, 100000};
int pn = 0, pr[100050];
bool np[100050] = {0};
int px, len, sol;
int mat[6][6];
int dp[10000];
inline void gen() {
  np[0] = np[1] = 1;
  for (int i = 2; i < 100050; i++) {
    if (np[i]) continue;
    pr[pn++] = i;
    if (i > 400) continue;
    for (int j = i * i; j < 100050; j += i) np[j] = 1;
  }
}
inline int rowval(int r, int vlen = 6) {
  int ret = 0;
  for (int i = 0; i < len; i++) ret = ret * 10 + (i < vlen ? mat[r][i] : 0);
  return ret;
}
inline int get() {
  int h = mat[3][1] * 1000 + mat[3][2] * 100 + mat[4][1] * 10 + mat[4][2];
  if (dp[h] < 0) {
    dp[h] = 0;
    for (int i = 0; i < 10; i++) {
      mat[3][3] = i;
      for (int j = 0; j < 10; j++) {
        mat[3][4] = mat[4][3] = j;
        if (np[rowval(3)]) continue;
        for (int k = 0; k < 10; k++) {
          mat[4][4] = k;
          if (np[rowval(4)]) continue;
          dp[h]++;
        }
      }
    }
  }
  return dp[h];
}
void dfs(int r) {
  if (len == 5 && r == 3) {
    sol += get();
    return;
  }
  if (r == len) {
    sol++;
    return;
  }
  int st = rowval(r, r);
  int ed = st + p10[len - r];
  int *si = lower_bound(pr, pr + pn, st);
  int *ei = lower_bound(pr, pr + pn, ed);
  for (int *pi = si; pi < ei; pi++) {
    int tmp = *pi;
    for (int i = len - 1; i >= r; i--) {
      mat[r][i] = mat[i][r] = tmp % 10;
      tmp /= 10;
    }
    dfs(r + 1);
  }
}
inline int solve() {
  int tmp = px;
  len = 0;
  while (tmp) {
    tmp /= 10;
    len++;
  }
  tmp = px;
  memset(mat, 0, sizeof(mat));
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < len; i++) {
    mat[0][len - i - 1] = mat[len - i - 1][0] = tmp % 10;
    tmp /= 10;
  }
  sol = 0;
  dfs(1);
  return sol;
}
int main(void) {
  int t;
  gen();
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &px);
    printf("%d\n", solve());
  }
  return 0;
}