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>
int p10[6];
int pi;
int npr[100000];
int c[5][100000], _c[5][100000];
int C(int p, int k) {
  if (_c[p][k]) return c[p][k];
  _c[p][k] = 1;
  c[p][k] = 0;
  int i;
  for (i = 0; i <= 9; i++) c[p][k] += !npr[k + p10[p] * i];
  return c[p][k];
}
int d[5][5];
int back(int n);
int back2(int i, int j, int pr, int now) {
  if (j >= 5)
    return C(4 - i, pr + now) * back(5 - i - 1);
  else {
    int r = 0;
    for (int k = 0; k <= 9; k++) {
      d[i][j] = d[j][i] = k;
      r += back2(i, j + 1, pr, now * 10 + k);
    }
    return r;
  }
}
int back(int n) {
  if (n == 0) return 1;
  int i, j;
  if (pi < p10[n - 1]) {
    for (i = 0; i < 5; i++) d[5 - n][i] = d[i][5 - n] = 0;
    return back(n - 1);
  } else if (p10[n - 1] <= pi && pi < p10[n]) {
    i = pi;
    for (j = 4; i; j--) {
      d[5 - n][j] = d[j][5 - n] = i % 10;
      i /= 10;
    }
    return back(n - 1);
  } else {
    i = 0;
    for (j = 0; j < 5 - n; j++) i = i * 10 + d[5 - n][j];
    for (; j < 5; j++) i *= 10;
    return back2(5 - n, 5 - n + 1, i, 0);
  }
}
int main() {
  int t, i, j;
  memset(npr, 0, sizeof(npr));
  npr[0] = npr[1] = 1;
  for (i = 2; i < 100000; i++) {
    if (npr[i]) continue;
    for (j = i + i; j < 100000; j += i) npr[j] = 1;
  }
  p10[0] = 1;
  for (i = 1; i <= 5; i++) p10[i] = p10[i - 1] * 10;
  for (scanf("%d", &t); t--;) {
    scanf("%d", &pi);
    printf("%d\n", back(5));
  }
  return 0;
}