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;
const double eps = 1e-10;
const int inf = (int)1e9;
const int maxn = (int)1e5 + 10;
int p[maxn];
int d1[10][10000], d1c[10];
int d2[100][1000], d2c[100];
int d3[1000][100], d3c[1000];
int d4[10000][10], d4c[10000];
int a[5][5];
int res = 0;
inline void go1() { res++; }
void go2() {
  int x = 0;
  for (int i = 0; i < 4; i++) x = x * 10 + a[4][i];
  res += d4c[x];
}
void go3() {
  int x = 0;
  for (int i = 0; i < 3; i++) x = x * 10 + a[3][i];
  for (int i = 0; i < d3c[x]; i++) {
    int h = d3[x][i];
    for (int i = 4; i > 2; i--) a[3][i] = a[i][3] = h % 10, h /= 10;
    go2();
  }
}
void go4() {
  int x = 0;
  for (int i = 0; i < 2; i++) x = x * 10 + a[2][i];
  for (int i = 0; i < d2c[x]; i++) {
    int h = d2[x][i];
    for (int i = 4; i > 1; i--) a[2][i] = a[i][2] = h % 10, h /= 10;
    go3();
  }
}
void go5() {
  int x = 0;
  for (int i = 0; i < 1; i++) x = x * 10 + a[1][i];
  for (int i = 0; i < d1c[x]; i++) {
    int h = d1[x][i];
    for (int i = 4; i > 0; i--) a[1][i] = a[i][1] = h % 10, h /= 10;
    go4();
  }
}
int main() {
  p[0] = p[1] = 1;
  for (int i = 2; i < maxn; i++)
    if (p[i] == 0)
      for (int j = 2; i * j < maxn; j++) p[i * j] = 1;
  for (int i = 0; i < 100000; i++) {
    if (p[i] == 0) {
      d1[i / 10000][d1c[i / 10000]++] = i;
      d2[i / 1000][d2c[i / 1000]++] = i;
      d3[i / 100][d3c[i / 100]++] = i;
      d4[i / 10][d4c[i / 10]++] = i;
    }
  }
  int tn;
  scanf("%d", &tn);
  while (tn-- > 0) {
    int n;
    scanf("%d", &n);
    res = 0;
    memset(a, 0, sizeof a);
    if (n < 100) {
      for (int i = 4; i >= 3; i--) a[3][i] = a[i][3] = n % 10, n /= 10;
      go2();
    } else if (n < 1000) {
      for (int i = 4; i >= 2; i--) a[2][i] = a[i][2] = n % 10, n /= 10;
      go3();
    } else if (n < 10000) {
      for (int i = 4; i >= 1; i--) a[1][i] = a[i][1] = n % 10, n /= 10;
      go4();
    } else if (n < 100000) {
      for (int i = 4; i >= 0; i--) a[0][i] = a[i][0] = n % 10, n /= 10;
      go5();
    }
    cout << res << endl;
  }
  return 0;
}